#############################################################################
#  $Id: configure.ac 671133 2023-08-08 19:52:02Z ivanov $
#  Derived from configure.in version 1.173.
# ==========================================================================
#
#                            PUBLIC DOMAIN NOTICE
#               National Center for Biotechnology Information
#
#  This software/database is a "United States Government Work" under the
#  terms of the United States Copyright Act.  It was written as part of
#  the author's official duties as a United States Government employee and
#  thus cannot be copyrighted.  This software/database is freely available
#  to the public for use. The National Library of Medicine and the U.S.
#  Government have not placed any restriction on its use or reproduction.
#
#  Although all reasonable efforts have been taken to ensure the accuracy
#  and reliability of the software and data, the NLM and the U.S.
#  Government do not and cannot warrant the performance or results that
#  may be obtained by using this software or data. The NLM and the U.S.
#  Government disclaim all warranties, express or implied, including
#  warranties of performance, merchantability or fitness for any particular
#  purpose.
#
#  Please cite the author in any work or product based on this material.
#
# ==========================================================================
#
# Authors:  Denis Vakatov, Aaron Ucko
#
# File Description:
#   Setup NCBI C++ Toolkit build tree - tuned for your platform, compiler, etc.
#   USAGE:
#    1) Process this file with "autoconf" to produce a "configure" script.
#    2) Run the resultant "configure" script to produce:
#      a) "<builddir>/inc/ncbiconf_unix.h"
#      b) "<builddir>/build/Makefile.mk"
#      c) other Makefile's and scripts in "<builddir>/build" and below
#
#############################################################################

AC_PREREQ(2.69)

dnl Early setup, most crucially for locking.  The diversion magic lets
dnl this occur before AC_INIT, which already interferes with other
dnl configure processes.

AC_DIVERT_PUSH(INIT_PREPARE)

# Check --with-3psw=.../--without-3psw early because a lot hinges on it
orig_NCBI=$NCBI
case "$with_3psw" in
   '' | yes | [[\$/][Nn]*:[SsLl]*] | [[Nn]*:[SsLl]*] )
      ncbi_favor_std_packages=no
      ;;
   [[SsLl]]*:* )
      ncbi_favor_std_packages=yes
      ;;
   [[SsLl]]* )
      AS_UNSET(NCBI)
      ;;
   no )
      if test "${with_ncbi_c-no}" != "no"; then
         AC_MSG_ERROR([incompatible options: --with-ncbi-c but --without-3psw])
      else
         with_ncbi_c=no
      fi
      if test "${with_aws_sdk-no}" != "no"; then
         AC_MSG_ERROR([incompatible options: --with-aws-sdk but --without-3psw])
      else
         with_aws_sdk=no
      fi
      if test "${with_google_cloud-no}" != "no"; then
         AC_MSG_ERROR([incompatible options: --with-google-cloud but --without-3psw])
      else
         with_google_cloud=no
      fi
      if test "${with_apache_arrow-no}" != "no"; then
         AC_MSG_ERROR([incompatible options: --with-apache-arrow but --without-3psw])
      else
         with_apache_arrow=no
      fi
      if test "${with_nlohmann_json-no}" != "no"; then
         AC_MSG_ERROR([incompatible options: --with-nlohmann-json but --without-3psw])
      else
         with_nlohmann_json=no
      fi
      if test "${with_yaml_cpp-no}" != "no"; then
         AC_MSG_ERROR([incompatible options: --with-yaml-cpp but --without-3psw])
      else
         with_yaml_cpp=no
      fi
      m4_foreach(X, [sss, sssutils, sssdb, vdb, ngs, ncbicrypt, libunwind,
                     z, bz2, lzo, zstd, pcre, mbedtls,
                     gmp, gcrypt, nettle, gnutls, openssl, krb5, boost, lmdb,
                     sybase, ftds, mysql, opengl, mesa, glut, glew, gl2ps,
                     wxwidgets, freetype, ftgl, fastcgi, fastcgipp,
                     bdb, orbacus, odbc,
                     python, perl, jni, sqlite3, mimetic,
                     sge, drmaa2, icu, sp, expat,
                     sablot, libxml, libxslt, libexslt, xerces, xalan, zorba,
                     oechem, muparser, hdf5, gif, jpeg, png, tiff, xpm, magic,
                     curl, gsoap, avro, cereal, sasl2,
                     mongodb, mongodb3, leveldb, liburing, rocksdb,
                     gmock, lapack,
                     libuv, libssh2, cassandra, nghttp2, h2o, influxdb,
                     libxlsxwriter, protobuf, grpc, msgsl, crc32c, hiredis,
                     librdkafka, cppkafka, thrift, opentracing, jaeger],
        [if test "${[with_]X-no}" != "no"; then
            AC_MSG_ERROR([incompatible options: --with-]X[ but --without-3psw])
         else
            [with_]X=no
         fi
        ])
      AS_UNSET(NCBI)
      ;;
   * )
      AC_MSG_ERROR([Unsupported option --with-3psw=$with_3psw])
      ;;
esac

if $srcdir/scripts/common/impl/get_lock.sh configure $$; then
    ac_clean_files=configure.lock
else
    exit 1
fi
# reconfigure.sh expects config.cache to exist; unconditionally clobber
# any command-line setting.
cache_file=config.cache
if test -z "$CONFIG_SITE" -a -r $srcdir/src/build-system/config.site; then
    CONFIG_SITE=$srcdir/src/build-system/config.site
fi
AC_DIVERT_POP

AC_INIT([ncbi-tools++],[0.0],[cpp-core@ncbi.nlm.nih.gov])
AC_CONFIG_SRCDIR(src/build-system/Makefile.mk.in)



#############################################################################


#### Describe all "--with-*" arguments -- for the usage printout on "--help"

## Title
AC_ARG_WITH(_,
   [===============================================================================])
AC_ARG_WITH(_,
   [=============== NCBI C++ Toolkit specific configuration flags =================])
AC_ARG_WITH(_,
   [===============================================================================])

## Code generation
AC_ARG_WITH(debug,
   [ --without-debug         build non-debug versions of libs and apps])
AC_ARG_WITH(max-debug,
   [ --with-max-debug        enable extra runtime checks (esp. of STL usage)])
AC_ARG_WITH(max-debug,
   [ --with-max-debug=thread ... including via GCC's thread sanitizer])
AC_ARG_WITH(symbols,
   [ --with-symbols          retain debugging symbols in non-debug mode])
AC_ARG_WITH(optimization,
   [ --without-optimization  turn off optimization flags in non-debug mode])
AC_ARG_WITH(sse42,
   [ --without-sse42         don't enable SSE 4.2 when optimizing])
AC_ARG_WITH(profiling,
   [ --with-profiling        build profiled versions of libs and apps])
AC_ARG_WITH(code-coverage,
   [ --with-code-coverage    track which code blocks have been exercised])
AC_ARG_WITH(tcheck,
   [ --with-tcheck(=DIR)     build for Intel Thread Checker (in DIR)])
AC_ARG_WITH(dll,
   [ --with-dll              build all libraries as DLLs])
AC_ARG_WITH(static,
   [ --with-static           build all libraries statically even if --with-dll])
AC_ARG_WITH(static-exe,
   [ --with-static-exe       build all executables as statically as possible])
AC_ARG_WITH(plugin-auto-load,
   [ --with-plugin-auto-load always enable the plugin manager by default])
AC_ARG_WITH(bundles,
   [ --with-bundles          build bundles in addition to dylibs on Mac OS X])
AC_ARG_WITH(bin-release,
   [ --with-bin-release      build executables suitable for public release])
AC_ARG_WITH(mt,
   [ --without-mt            support only single-threaded operation])
AC_ARG_WITH(openmp,
   [ --with-openmp           enable OpenMP extensions for all projects])
AC_ARG_WITH(64,
   [ --with-64               compile to 64-bit code])
AC_ARG_WITH(exe,
   [ --without-exe           do not build executables])
AC_ARG_WITH(runpath,
   [ --with-runpath=PATH     specify the usual runtime path to DLLs])
AC_ARG_WITH(relative-runpath,
   [ --with-relative-runpath=P specify an executable-relative DLL search path])
AC_ARG_WITH(hard-runpath,
   [ --with-hard-runpath     hard-code runtime path, ignoring LD_LIBRARY_PATH])
AC_ARG_WITH(lfs,
   [ --with-lfs              enable large file support to the extent possible])
AC_ARG_WITH(limited-linker,
   [ --with-limited-linker   don't attempt to build especially large projects])
AC_ARG_WITH(experimental,
   [ --with-experimental=... enable named experimental feature(s): Int{4,8}GI,StrictGI,PSGLoader,BM64,C++20,C2X])
AC_ARG_WITH(skew-guard,
   [ --with-skew-guard       catch incomplete rebuilds])

## Scripts, make features, and directory naming
AC_ARG_WITH(extra-action,
   [ --with-extra-action=    script to call after the configuration is complete])
AC_ARG_WITH(autodep,
   [ --with-autodep          automatic generation of dependencies (GNU make)])
AC_ARG_WITH(build-root,
   [ --with-build-root=DIR   specify a non-default build directory name])
AC_ARG_WITH(fake-root,
   [ --with-fake-root=DIR    appear to have been built under DIR])
AC_ARG_WITH(suffix,
   [ --without-suffix        no Release/Debug, MT or DLL sfx in the build dir name])
AC_ARG_WITH(hostspec,
   [ --with-hostspec         add full host specs to the build dir name])
AC_ARG_WITH(version,
   [ --without-version       don't always include the cplr ver in the bd name])
AC_ARG_WITH(build-root-sfx,
   [ --with-build-root-sfx=X add a user-specified suffix to the build dir name])
AC_ARG_WITH(execopy,
   [ --without-execopy       do not copy built executables to the BIN area])
AC_ARG_WITH(bincopy,
   [ --with-bincopy          populate lib and bin with copies, not hard links])
AC_ARG_WITH(lib-rebuilds,
   [ --with-lib-rebuilds     ensure that apps use up-to-date libraries])
AC_ARG_WITH(lib-rebuilds,
   [ --with-lib-rebuilds=ask ask whether to update each app's libraries])dnl'
AC_ARG_WITH(deactivation,
   [ --without-deactivation  keep old copies of libraries that no longer build])
AC_ARG_WITH(makefile-auto-update,
   [ --without-makefile-auto-update  do not auto-update generated makefiles])
AC_ARG_WITH(projects,
   [ --with-projects=FILE    build projects listed in FILE by default])
AC_ARG_WITH(flat-makefile,
   [ --without-flat-makefile do not generate an all-encompassing flat makefile])
AC_ARG_WITH(configure-dialog,
   [ --with-configure-dialog allow interactive flat makefile project selection])
AC_ARG_WITH(saved-settings,
   [ --with-saved-settings=F load configuration settings from the file F])
AC_ARG_WITH(check,
   [ --with-check            run test suite after the build])
AC_ARG_WITH(check-tools,
   [ --with-check-tools=...  use the specified tools for testing])
AC_ARG_WITH(ncbi-public,
   [ --with-ncbi-public      ensure compatibility for all in-house platforms])
AC_ARG_WITH(strip,
   [ --with-strip            strip binaries at build time])
AC_ARG_WITH(pch,
   [ --with-pch              use precompiled headers if possible])
AC_ARG_WITH(caution,
   [ --with-caution          cancel configuration unconditionally when in doubt])
AC_ARG_WITH(caution,
   [ --without-caution       proceed without asking when in doubt])
AC_ARG_WITH(ccache,
   [ --without-ccache        do not automatically use ccache if available])
AC_ARG_WITH(distcc,
   [ --without-distcc        do not automatically use distcc if available])

## NCBI packages
AC_ARG_WITH(ncbi-c,
   [ --with-ncbi-c=DIR       use NCBI C Toolkit installation in DIR])
AC_ARG_WITH(ncbi-c,
   [ --without-ncbi-c        do not use NCBI C Toolkit])
AC_ARG_WITH(sss,
   [ --with-sss=DIR          use NCBI SSS installation in DIR])
AC_ARG_WITH(sss,
   [ --without-sss           do not use NCBI SSS libraries])
AC_ARG_WITH(sssutils,
   [ --without-utils         do not use NCBI SSS UTIL library])
AC_ARG_WITH(sssdb,
   [ --without-sssdb         do not use NCBI SSS DB library])
AC_ARG_WITH(included-sss,
   [ --with-included-sss     use the in-tree copy of SSS])
AC_ARG_WITH(vdb,
   [ --with-vdb=DIR          use NCBI SRA/VDB Toolkit installation in DIR])
AC_ARG_WITH(vdb,
   [ --without-vdb           do not use the NCBI SRA/VDB Toolkit])
AC_ARG_WITH(downloaded-vdb,
   [ --with-downloaded-vdb   download and build SRA/VDB from GitHub])
AC_ARG_WITH(static-vdb,
   [ --with-static-vdb       always link statically against SRA/VDB])
AC_ARG_WITH(ngs,
   [ --with-ngs=DIR          use NCBI NGS SDK installation in DIR])
AC_ARG_WITH(ngs,
   [ --without-ngs           do not use the NCBI NGS SDK])
AC_ARG_WITH(ncbicrypt,
   [ --with-ncbicrypt=DIR    use ncbicrypt installation in DIR])
AC_ARG_WITH(ncbicrypt,
   [ --without-ncbicrypt     do not use ncbicrypt])

## Third-party and system packages
AC_ARG_WITH(libunwind,
   [ --with-libunwind(=DIR)  use libunwind (in DIR)])
AC_ARG_WITH(libdw,
   [ --with-libdw=DIR        use elfutils libdw installation in DIR])
AC_ARG_WITH(libdw,
   [ --without-libdw         do not use elfutils libdw])
AC_ARG_WITH(backward-cpp,
   [ --with-backward-cpp=DIR use backward-cpp installation in DIR])
AC_ARG_WITH(backward-cpp,
   [ --without-backward-cpp  do not use backward-cpp])
AC_ARG_WITH(backward-cpp-sig,
   [ --with-backward-cpp-sig  allow backward-cpp to also handle signals])
AC_ARG_WITH(z,
   [ --with-z=DIR            use zlib installation in DIR])
AC_ARG_WITH(z,
   [ --without-z             use internal copy of zlib])
AC_ARG_WITH(bz2,
   [ --with-bz2=DIR          use bzlib installation in DIR])
AC_ARG_WITH(bz2,
   [ --without-bz2           use internal copy of bzlib])
AC_ARG_WITH(lzo,
   [ --with-lzo=DIR          use LZO installation in DIR (requires 2.x or up)])
AC_ARG_WITH(lzo,
   [ --without-lzo           do not use LZO])
AC_ARG_WITH(zstd,
   [ --with-zstd=DIR         use Zstandard installation in DIR])
AC_ARG_WITH(zstd,
   [ --without-zstd          do not use Zstandard])
AC_ARG_WITH(pcre,
   [ --with-pcre=DIR         use PCRE installation in DIR])
AC_ARG_WITH(pcre,
   [ --without-pcre          use internal copy of PCRE])
AC_ARG_WITH(mbedtls,
   [ --with-mbedtls(=DIR)    use external mbedTLS installation (in DIR)])
AC_ARG_WITH(gmp,
   [ --with-gmp=DIR          use GMP installation in DIR])
AC_ARG_WITH(gmp,
   [ --without-gmp           do not use GMP])
AC_ARG_WITH(gcrypt,
   [ --with-gcrypt=DIR       use gcrypt installation in DIR])
AC_ARG_WITH(gcrypt,
   [ --without-gcrypt        do not use gcrypt])
AC_ARG_WITH(nettle,
   [ --with-nettle=DIR       use Nettle installation in DIR])
AC_ARG_WITH(nettle,
   [ --without-nettle        do not use Nettle])
AC_ARG_WITH(gnutls,
   [ --with-gnutls=DIR       use GNUTLS installation in DIR])
AC_ARG_WITH(static-gnutls,
   [ --with-static-gnutls    link GNUTLS statically if possible])
AC_ARG_WITH(openssl,
   [ --with-openssl=DIR      use OpenSSL installation in DIR])
AC_ARG_WITH(openssl,
   [ --without-openssl       do not use OpenSSL])
AC_ARG_WITH(krb5,
   [ --with-krb5=DIR         use Kerberos 5 installation in DIR])
AC_ARG_WITH(krb5,
   [ --without-krb5          do not use Kerberos 5])
AC_ARG_WITH(sybase,
   [ --without-sybase        do not use SYBASE libraries])
AC_ARG_WITH(sybase-local,
   [ --with-sybase-local=DIR use local SYBASE install (DIR is optional)])
AC_ARG_WITH(sybase-new,
   [ --with-sybase-new       use newer SYBASE install (12.5 rather than 12.0)])
AC_ARG_WITH(ftds,
   [ --without-ftds          do not use FreeTDS libraries])
AC_ARG_WITH(ftds,
   [ --with-ftds=DIR         use FreeTDS installation in DIR])
AC_ARG_WITH(ftds-renamed,
   [ --without-ftds-renamed  do not rename Sybase DBLIB symbols in built-in FTDS])
AC_ARG_WITH(mysql,
   [ --without-mysql         do not use MySQL])
AC_ARG_WITH(mysql,
   [ --with-mysql=DIR        use MySQL installation in DIR])
AC_ARG_WITH(opengl,
   [ --without-opengl        do not use OpenGL])
AC_ARG_WITH(opengl,
   [ --with-opengl=DIR       use OpenGL installation in DIR])
AC_ARG_WITH(mesa,
   [ --without-mesa          do not use MESA off-screen OpenGL])
AC_ARG_WITH(mesa,
   [ --with-mesa=DIR         use MESA installation in DIR])
AC_ARG_WITH(glut,
   [ --without-glut          do not use GLUT])
AC_ARG_WITH(glut,
   [ --with-glut=DIR         use GLUT installation in DIR])
AC_ARG_WITH(glew,
   [ --without-glew          do not use GLEW])
AC_ARG_WITH(glew,
   [ --with-glew=DIR         use GLEW installation in DIR])
AC_ARG_WITH(glew-mx,
   [ --with-glew-mx          insist on a multi-context-ready GLEW installation])
AC_ARG_WITH(gl2ps,
   [ --without-gl2ps         do not use GL2PS])
AC_ARG_WITH(gl2ps,
   [ --with-gl2ps=DIR        use GL2PS installation in DIR])
AC_ARG_WITH(wxwidgets,
   [ --without-wxwidgets     do not use wxWidgets (2.6+)])
AC_ARG_WITH(wxwidgets,
   [ --with-wxwidgets=DIR    use wxWidgets installation in DIR])
AC_ARG_WITH(wxwidgets-ucs,
   [ --with-wxwidgets-ucs    use Unicode builds of wxWidgets])
AC_ARG_WITH(wxwidgets-ucs,
   [ --without-wxwidgets-ucs do not use Unicode builds of wxWidgets])
AC_ARG_WITH(freetype,
   [ --without-freetype      do not use FreeType])
AC_ARG_WITH(freetype,
   [ --with-freetype=DIR     use FreeType installation in DIR])
AC_ARG_WITH(ftgl,
   [ --without-ftgl          do not use FTGL])
AC_ARG_WITH(ftgl,
   [ --with-ftgl=DIR         use FTGL installation in DIR])
AC_ARG_WITH(fastcgi,
   [ --without-fastcgi       do not use Fast-CGI library])
AC_ARG_WITH(fastcgi,
   [ --with-fastcgi=VERSION  use Fast-CGI installation in \$NCBI/fcgi-VERSION])
AC_ARG_WITH(fastcgi,
   [ --with-fastcgi=DIR      use Fast-CGI installation in DIR])
AC_ARG_WITH(fastcgipp,
   [ --without-fastcgipp     do not use fastcgipp library])
AC_ARG_WITH(fastcgipp,
   [ --with-fastcgipp=DIR    use fastcgipp installation in DIR])
AC_ARG_WITH(bdb,
   [ --without-bdb           do not use Berkeley DB library])
AC_ARG_WITH(bdb,
   [ --with-bdb=VERSION      use DB installation in \$NCBI/BerkeleyDB-VERSION])
AC_ARG_WITH(bdb,
   [ --with-bdb=DIR          use Berkeley DB installation in DIR])
AC_ARG_WITH(sp,
   [ --without-sp            do not use SP libraries])
AC_ARG_WITH(orbacus,
   [ --without-orbacus       do not use ORBacus CORBA libraries])
AC_ARG_WITH(orbacus,
   [ --with-orbacus=DIR      use ORBacus installation in DIR])
AC_ARG_WITH(odbc,
   [ --with-odbc=DIR         use ODBC installation in DIR])
AC_ARG_WITH(python,
   [ --with-python=DIR       use Python installation in DIR])
AC_ARG_WITH(python,
   [ --without-python        do not use Python])
AC_ARG_WITH(perl,
   [ --with-perl=DIR         use Perl installation in DIR])
AC_ARG_WITH(perl,
   [ --without-perl          do not use Perl])
AC_ARG_WITH(jni,
   [ --with-jni(=JDK-DIR)    build Java bindings (against the JDK in JDK-DIR)])
AC_ARG_WITH(boost,
   [ --with-boost=DIR        use Boost installation in DIR])
AC_ARG_WITH(boost,
   [ --without-boost         do not use Boost])
AC_ARG_WITH(boost-tag,
   [ --with-boost-tag=TAG    use TAG as the tag appended to Boost library names])
AC_ARG_WITH(boost-tag,
   [ --without-boost-tag     use untagged Boost library names])
AC_ARG_WITH(sqlite3,
   [ --with-sqlite3=DIR      use SQLite 3.x installation in DIR])
AC_ARG_WITH(sqlite3,
   [ --without-sqlite3       do not use SQLite 3.x])
AC_ARG_WITH(icu,
   [ --with-icu=DIR          use ICU installation in DIR])
AC_ARG_WITH(icu,
   [ --without-icu           do not use ICU])
AC_ARG_WITH(expat,
   [ --with-expat=DIR        use Expat installation in DIR])
AC_ARG_WITH(expat,
   [ --without-expat         do not use Expat])
AC_ARG_WITH(sablot,
   [ --with-sablot=DIR       use Sablotron installation in DIR])
AC_ARG_WITH(sablot,
   [ --without-sablot        do not use Sablotron])
AC_ARG_WITH(libxml,
   [ --with-libxml=DIR       use libxml2 installation in DIR])
AC_ARG_WITH(libxml,
   [ --without-libxml        do not use libxml2])
AC_ARG_WITH(libxslt,
   [ --with-libxslt=DIR      use libxslt installation in DIR])
AC_ARG_WITH(libxslt,
   [ --without-libxslt       do not use libxslt])
AC_ARG_WITH(libexslt,
   [ --with-libexslt=DIR     use libexslt installation in DIR])
AC_ARG_WITH(libexslt,
   [ --without-libexslt      do not use libexslt])
AC_ARG_WITH(xerces,
   [ --with-xerces=DIR       use Xerces-C++ installation in DIR])
AC_ARG_WITH(xerces,
   [ --without-xerces        do not use Xerces-C++])
AC_ARG_WITH(xalan,
   [ --with-xalan=DIR        use Xalan-C++ installation in DIR])
AC_ARG_WITH(xalan,
   [ --without-xalan         do not use Xalan-C++])
AC_ARG_WITH(zorba,
   [ --with-zorba=DIR        use Zorba installation in DIR])
AC_ARG_WITH(zorba,
   [ --without-zorba         do not use Zorba])
AC_ARG_WITH(oechem,
   [ --with-oechem=DIR       use OpenEye OEChem installation in DIR])
AC_ARG_WITH(oechem,
   [ --without-oechem        do not use OEChem])
AC_ARG_WITH(sge,
   [ --with-sge=DIR          use Sun/Univa Grid Engine installation in DIR])
AC_ARG_WITH(sge,
   [ --without-sge           do not use Sun/Univa Grid Engine])
AC_ARG_WITH(drmaa2,
   [ --with-drmaa2=DIR       use DRMAA2 grid API installation in DIR])
AC_ARG_WITH(drmaa2,
   [ --without-drmaa2        do not use DRMAA2 grid API])
AC_ARG_WITH(muparser,
   [ --with-muparser=DIR     use muParser installation in DIR])
AC_ARG_WITH(muparser,
   [ --without-muparser      do not use muParser])
AC_ARG_WITH(hdf5,
   [ --with-hdf5=DIR         use HDF5 installation in DIR])
AC_ARG_WITH(hdf5,
   [ --without-hdf5          do not use HDF5])
AC_ARG_WITH(gif,
   [ --with-gif=DIR          use lib(un)gif installation in DIR])
AC_ARG_WITH(gif,
   [ --without-gif           do not use lib(un)gif])
AC_ARG_WITH(jpeg,
   [ --with-jpeg=DIR         use libjpeg installation in DIR])
AC_ARG_WITH(jpeg,
   [ --without-jpeg          do not use libjpeg])
AC_ARG_WITH(png,
   [ --with-png=DIR          use libpng installation in DIR])
AC_ARG_WITH(png,
   [ --without-png           do not use libpng])
AC_ARG_WITH(tiff,
   [ --with-tiff=DIR         use libtiff installation in DIR])
AC_ARG_WITH(tiff,
   [ --without-tiff          do not use libtiff])
AC_ARG_WITH(xpm,
   [ --with-xpm=DIR          use libXpm installation in DIR])
AC_ARG_WITH(xpm,
   [ --without-xpm           do not use libXpm])
AC_ARG_WITH(magic,
   [ --with-magic=DIR        use libmagic installation in DIR])
AC_ARG_WITH(magic,
   [ --without-magic         do not use libmagic])
AC_ARG_WITH(curl,
   [ --with-curl=DIR         use libcurl installation in DIR])
AC_ARG_WITH(curl,
   [ --without-curl          do not use libcurl])
AC_ARG_WITH(mimetic,
   [ --with-mimetic=DIR      use libmimetic installation in DIR])
AC_ARG_WITH(mimetic,
   [ --without-mimetic       do not use libmimetic])
AC_ARG_WITH(gsoap,
   [ --with-gsoap=DIR        use gSOAP++ installation in DIR])
AC_ARG_WITH(gsoap,
   [ --without-gsoap         do not use gSOAP++])
AC_ARG_WITH(avro,
   [ --with-avro=DIR         use Apache Avro installation in DIR])
AC_ARG_WITH(avro,
   [ --without-avro          do not use Apache Avro])
AC_ARG_WITH(cereal,
   [ --with-cereal=DIR       use USC Cereal installation in DIR])
AC_ARG_WITH(cereal,
   [ --without-cereal        do not use USC Cereal])
AC_ARG_WITH(sasl2,
   [ --with-sasl2=DIR        use SASL 2 installation in DIR])
AC_ARG_WITH(sasl2,
   [ --without-sasl2         do not use SASL 2])
AC_ARG_WITH(mongodb,
   [ --with-mongodb=DIR      use legacy MongoDB installation in DIR])
AC_ARG_WITH(mongodb,
   [ --without-mongodb       do not use legacy MongoDB])
AC_ARG_WITH(mongodb3,
   [ --with-mongodb3=DIR     use MongoDB 3 installation in DIR])
AC_ARG_WITH(mongodb3,
   [ --without-mongodb3      do not use MongoDB 3])
AC_ARG_WITH(leveldb,
   [ --with-leveldb=DIR      use LevelDB installation in DIR])
AC_ARG_WITH(leveldb,
   [ --without-leveldb       do not use LevelDB])
AC_ARG_WITH(liburing,
   [ --with-liburing=DIR     use liburing installation in DIR])
AC_ARG_WITH(liburing,
   [ --without-liburing      do not use liburing])
AC_ARG_WITH(rocksdb,
   [ --with-rocksdb=DIR      use RocksDB installation in DIR])
AC_ARG_WITH(rocksdb,
   [ --without-rocksdb       do not use RocksDB])
AC_ARG_WITH(gmock,
   [ --with-gmock=DIR        use Google Mock installation in DIR])
AC_ARG_WITH(gmock,
   [ --without-gmock         do not use Google Mock])
AC_ARG_WITH(lapack,
   [ --with-lapack=DIR       use LAPACK installation in DIR])
AC_ARG_WITH(lapack,
   [ --without-lapack        do not use LAPACK])
AC_ARG_WITH(lmdb,
   [ --with-lmdb=DIR         use LMDB installation in DIR])
AC_ARG_WITH(lmdb,
   [ --without-lmdb          use internal copy of LMDB])
AC_ARG_WITH(libuv,
   [ --with-libuv=DIR        use libuv installation in DIR])
AC_ARG_WITH(libuv,
   [ --without-libuv         do not use libuv])
AC_ARG_WITH(libssh2,
   [ --with-libssh2=DIR      use libssh2 installation in DIR])
AC_ARG_WITH(libssh2,
   [ --without-libssh2       do not use libssh2])
AC_ARG_WITH(cassandra,
   [ --with-cassandra=DIR    use Datastax Cassandra driver installation in DIR])
AC_ARG_WITH(cassandra,
   [ --without-cassandra     do not use Datastax Cassandra driver])
AC_ARG_WITH(nghttp2,
   [ --with-nghttp2=DIR      use nghttp2 installation in DIR])
AC_ARG_WITH(nghttp2,
   [ --without-nghttp2       do not use nghttp2])
AC_ARG_WITH(h2o,
   [ --with-h2o=DIR          use h2o installation in DIR])
AC_ARG_WITH(h2o,
   [ --without-h2o           do not use h2o])
AC_ARG_WITH(influxdb,
   [ --with-influxdb=DIR     use influxdb-cpp installation in DIR])
AC_ARG_WITH(influxdb,
   [ --without-influxdb      do not use influxdb-cpp])
AC_ARG_WITH(libxlsxwriter,
   [ --with-libxlsxwriter=DIR use libxlsxwriter installation in DIR])
AC_ARG_WITH(libxlsxwriter,
   [ --without-libxlsxwriter do not use libxlsxwriter])
AC_ARG_WITH(protobuf,
   [ --with-protobuf=DIR     use protocol buffers installation in DIR])
AC_ARG_WITH(protobuf,
   [ --without-protobuf      do not use protocol buffers])
AC_ARG_WITH(grpc,
   [ --with-grpc=DIR         use GRPC (and protobuf) installation in DIR])
AC_ARG_WITH(grpc,
   [ --without-grpc          do not use GRPC])
AC_ARG_WITH(msgsl,
   [ --with-msgsl=DIR        use Guideline Support Library installation in DIR])
AC_ARG_WITH(msgsl,
   [ --without-msgsl         do not use the Guideline Support Library])
AC_ARG_WITH(aws-sdk,
   [ --with-aws-sdk=DIR      use Amazon Web Services SDK installation in DIR])
AC_ARG_WITH(aws-sdk,
   [ --without-aws-sdk       do not use the Amazon Web Services SDK])
AC_ARG_WITH(crc32c,
   [ --with-crc32c=DIR       use fast CRC32C installation in DIR])
AC_ARG_WITH(crc32c,
   [ --without-crc32c        do not use fast CRC32C])
AC_ARG_WITH(google-cloud,
   [ --with-google-cloud=DIR use Google Cloud C++ interface in DIR])
AC_ARG_WITH(google-cloud,
   [ --without-google-cloud  do not use Google Cloud])
AC_ARG_WITH(hiredis,
   [ --with-hiredis=DIR      use Hiredis installation in DIR])
AC_ARG_WITH(hiredis,
   [ --without-hiredis       do not use Hiredis])
AC_ARG_WITH(apache-arrow,
   [ --with-apache-arrow=DIR use Apache Arrow installation in DIR])
AC_ARG_WITH(apache-arrow,
   [ --without-apache-arrow  do not use Apache Arrow])
AC_ARG_WITH(librdkafka,
   [ --with-librdkafka=DIR   use librdkafka installation in DIR])
AC_ARG_WITH(librdkafka,
   [ --without-librdkafka    do not use librdkafka])
AC_ARG_WITH(cppkafka,
   [ --with-cppkafka=DIR     use cppkafka installation in DIR])
AC_ARG_WITH(cppkafka,
   [ --without-cppkafka      do not use cppkafka])
AC_ARG_WITH(thrift,
   [ --with-thrift=DIR       use Apache Thrift installation in DIR])
AC_ARG_WITH(thrift,
   [ --without-thrift        do not use Apache Thrift])
AC_ARG_WITH(nlohmann-json,
   [ --with-nlohmann-json=DIR use JSON for Modern C++ installation in DIR])
AC_ARG_WITH(nlohmann-json,
   [ --without-nlohmann-json do not use JSON for Modern C++])
AC_ARG_WITH(yaml-cpp,
   [ --with-yaml-cpp=DIR     use yaml-cpp installation in DIR])
AC_ARG_WITH(yaml-cpp,
   [ --without-yaml-cpp      do not use yaml-cpp])
AC_ARG_WITH(opentracing,
   [ --with-opentracing=DIR  use OpenTracing installation in DIR])
AC_ARG_WITH(opentracing,
   [ --without-opentracing   do not use OpenTracing])
AC_ARG_WITH(jaeger,
   [ --with-jaeger=DIR       use Jaeger Tracing installation in DIR])
AC_ARG_WITH(jaeger,
   [ --without-jaeger        do not use Jaeger tracing])
AC_ARG_WITH(3psw,
   [ --with-3psw=std:netopt  favor standard (system) builds of the above pkgs.])
AC_ARG_WITH(3psw,
   [ --without-3psw          do not use any of the above packages])

## Optional projects
dnl AC_ARG_WITH(connext,
dnl    [ --without-connext       do not build non-public CONNECT library extensions])
dnl AC_ARG_WITH(serial,
dnl    [ --without-serial        do not build the serialization library and tools])
dnl AC_ARG_WITH(objects,
dnl    [ --without-objects       do not generate/build serializeable objects from ASNs])
dnl AC_ARG_WITH(dbapi,
dnl    [ --without-dbapi         do not build database connectivity libraries])
AC_ARG_WITH(app,
   [ --without-app           do not build standalone applications like ID1_FETCH])
AC_ARG_WITH(ctools,
   [ --without-ctools        do not build NCBI C Toolkit based projects])
AC_ARG_WITH(gui,
   [ --without-gui           do not build most graphical projects])
dnl AC_ARG_WITH(algo,
dnl    [ --without-algo          do not build CPU-intensive algorithms])
AC_ARG_WITH(internal,
   [ --with-internal         always try to build internal projects])
AC_ARG_WITH(internal,
   [ --without-internal      never build internal projects])
AC_ARG_WITH(gbench,
   [ --with-gbench           ensure that Genome Workbench can be built])
AC_ARG_WITH(gbench,
   [ --without-gbench        do not build Genome Workbench])

## Manuals
AC_ARG_WITH(manuals,
   [***** See also HTML documentation in ./doc/index.html *****])


AC_DIVERT_PUSH(PARSE_ARGS)
dnl As of Autoconf 2.60, this needs to run too early for config.log,
dnl to which AC_MSG_ERROR normally copies its output, to be available.
m4_rename([AS_MESSAGE_LOG_FD], [NCBI_ORIG_ASMLFD])
m4_define([AS_MESSAGE_LOG_FD], [])
#### Check the passed arguments against the list of available ones
x_with_list="\
debug max-debug max-debug=thread symbols optimization sse42 \
profiling code-coverage tcheck dll static static-exe \
plugin-auto-load bundles bin-release mt 64 exe runpath hard-runpath \
lfs limited-linker skew-guard openmp \
autodep suffix hostspec version execopy bincopy lib-rebuilds lib-rebuilds=ask \
deactivation makefile-auto-update projects flat-makefile configure-dialog \
check ncbi-public strip pch caution ccache distcc \
ncbi-c wxwidgets wxwidgets-ucs fastcgi fastcgipp \
sss sssdb sssutils included-sss \
geo included-geo vdb downloaded-vdb static-vdb ngs ncbicrypt libunwind libdw \
backward-cpp backward-cpp-sig \
z bz2 lzo zstd pcre mbedtls \
gmp gcrypt nettle gnutls static-gnutls openssl krb5 \
sybase sybase-local sybase-new ftds mysql \
orbacus freetype ftgl opengl mesa glut glew glew-mx gl2ps \
bdb python perl jni sqlite3 icu boost boost-tag \
sp expat sablot libxml libxslt libexslt xerces xalan zorba \
oechem sge drmaa2 muparser hdf5 \
gif jpeg tiff png xpm \
magic curl mimetic gsoap avro cereal sasl2 \
mongodb mongodb3 leveldb liburing rocksdb gmock lapack lmdb \
libuv libssh2 cassandra nghttp2 h2o influxdb \
libxlsxwriter protobuf grpc msgsl aws-sdk crc32c google-cloud hiredis \
apache-arrow librdkafka cppkafka \
thrift nlohmann-json yaml-cpp opentracing jaeger \
3psw local-lbsm ncbi-crypt connext \
serial objects dbapi app ctools gui algo internal gbench"

changequote(, )dnl
x_with_list=`echo "$x_with_list" | sed 's/\([^ ][^ ]*\)/--with-\1 --without-\1/g'`
changequote([, ])dnl


for x_arg in "$@" ; do
   if test -z "$x_arg" ; then
      continue
   fi

   x_okay=
   for x_desc in $x_with_list ; do
      if test "$x_arg" = "$x_desc" ; then
         x_okay="okay"
         break
      fi
   done
   if test "$x_okay" = "okay" ; then
      continue
   fi

   case "$x_arg" in
      --with-extra-action= | --exec-prefix= | --with-projects= | --srcdir= \
      | --cache-file= | --build= | --host= | --target= | --with-runpath= \
      | --with-relative-runpath= | --x-includes= | --x-libraries= )
      AC_MSG_ERROR([$x_arg:  requires value;  use --help to show usage])
      ;;

      --with-projects=* | --with-saved-settings=* )
      # Confirm that the specified file exists and is readable.
      file=`echo $x_arg | sed -e 's/^[[^=]]*=//'`
      case "$file" in
         /* ) ;;
         *  ) file=$srcdir/$file ;;
      esac
      if test -f "$file"; then
         if test -r "$file"; then
            :
         else
            AC_MSG_ERROR([$x_arg:  requires a readable file; use --help to show usage])
         fi
      else
         AC_MSG_ERROR([$x_arg:  requires a (readable) file; use --help to show usage])
      fi
      ;;

      --with-vdb=rc ) ;;

      --srcdir=* | --x-includes=* | --x-libraries=* | --with-tcheck=* \
      | --with-ncbi-c=* | --with-sss=* | --with-vdb=* | --with-ngs=* \
      | --with-ncbicrypt=* \
      | --with-libunwind=* | --with-libdw=* | --with-backward-cpp=* \
      | --with-z=* | --with-bz2=* | --with-lzo=* | --with-zstd=* \
      | --with-pcre=* | --with-mbedtls=* \
      | --with-gmp=* | --with-gcrypt=* | --with-nettle=* \
      | --with-gnutls=* | --with-openssl=* | --with-krb5=* \
      | --with-sybase-local=* | --with-ftds=*/* | --with-mysql=* \
      | --with-opengl=* | --with-mesa=* | --with-glut=* | --with-glew=* \
      | --with-gl2ps=* \
      | --with-wxwidgets=* | --with-freetype=* | --with-ftgl=* \
      | --with-fastcgi=*/* | --with-fastcgipp=* | --with-bdb=*/* \
      | --with-orbacus=* \
      | --with-odbc=* | --with-python=* | --with-perl=* | --with-jni=* \
      | --with-boost=* | --with-sqlite3=* | --with-icu=* | --with-expat=* \
      | --with-sablot=* | --with-libxml=* | --with-libxslt=* | --with-exslt=* \
      | --with-xerces=* | --with-xalan=* | --with-zorba=* | --with-oechem=* \
      | --with-sge=* | --with-drmaa2=* | --with-muparser=* \
      | --with-hdf5=* | --with-gif=* \
      | --with-jpeg=* | --with-png=* | --with-tiff=* | --with-xpm=* \
      | --with-magic=* | --with-curl=* | --with-mimetic=* | --with-gsoap=* \
      | --with-avro=* | --with-cereal=* | --with-sasl2=* \
      | --with-mongodb=* | --with-mongodb3=* | --with-leveldb=* \
      | --with-liburing=* | --with-rocksdb=* \
      | --with-gmock=* | --with-lapack=* | --with-lmdb=* | --with-libuv=* \
      | --with-libssh2=* | --with-cassandra=* | --with-nghttp2=* \
      | --with-h2o=* | --with-influxdb=* | --with-libxlsxwriter=* \
      | --with-protobuf=* | --with-grpc=* | --with-msgsl=* | --with-aws-sdk=* \
      | --with-crc32c=* | --with-google-cloud=* \
      | --with-hiredis=* | --with-librdkafka=* | --with-cppkafka=* \
      | --with-thrift=* | --with-nlohmann-json=* | --with-yaml-cpp=* \
      | --with-opentracing=* | --with-jaeger=* )
      # Confirm that the specified directory exists and is readable.
      dir=`echo $x_arg | sed -e 's/^[[^=]]*=//'`
      case "$x_arg" in
         --srcdir=* | --*=/* ) ;;
         *  ) dir=$srcdir/$dir ;;
      esac
      if test -d "$dir"; then
         if test -r "$dir"; then
            :
         else
            AC_MSG_ERROR([$x_arg:  requires a readable directory; use --help to show usage])
         fi
      else
         AC_MSG_ERROR([$x_arg:  requires a (readable) directory; use --help to show usage])
      fi
      ;;

      [[A-Z]*=*] | -h | --help | --help=* | -V | --version | -q | --quiet \
      | --silent | --cache-file=* | -C | --config-cache | -n | --no-create \
      | --no-recursion | --prefix=* | --exec-prefix=* | --bindir=* \
      | --libdir=* | --includedir=* | --build=* | --host=* | --target=* \
      | --mandir=* | --infodir=* | --docdir=* | --htmldir=* \
      | --datadir=* | --sysconfdir=* | --localstatedir=* \
      | --with-runpath=* | --with-relative-runpath=* \
      | --with-experimental=* | --with-extra-action=* | --with-build-root=* \
      | --with-fake-root=* | --with-build-root-sfx=* | --with-check=* \
      | --with-check-tools=* | --with-ftds=[[0-9]]* | --with-fastcgi=[[0-9]]* \
      | --with-bdb=[[1-9]]* | --with-boost-tag=* | --with-3psw=* )
      ;;

      * )
      AC_MSG_ERROR([$x_arg:  unknown option;  use --help to show usage])
      ;;
   esac
done
m4_undefine([AS_MESSAGE_LOG_FD])
m4_rename([NCBI_ORIG_ASMLFD], [AS_MESSAGE_LOG_FD])
AC_DIVERT_POP


if test "$with_gbench" = "yes" ; then
   m4_foreach(OPT, [dll,mt,gui,exe,serial,objects,algo,glew,wxwidgets,ftgl,sqlite3,bdb,boost,xslt],
     [if test "$[with_]OPT" = "no"; then
         AC_MSG_ERROR([incompatible options: --without-]OPT[ but --with-gbench])
      else
         : ${[with_]OPT:=yes}
      fi
     ])
   : ${with_projects=scripts/projects/ncbi_gbench.lst}
elif test "$with_jni" = "yes" ; then
   m4_foreach(OPT, [dll,mt],
     [if test "$[with_]OPT" = "no"; then
         AC_MSG_ERROR([incompatible options: --without-]OPT[ but --with-jni])
      else
         [with_]OPT=yes
      fi
     ])
   : ${with_exe=no}
fi

if test "$with_bin_release" = "yes" ; then
   # Default some other options accordingly
   : ${with_ncbi_public=yes}
   : ${with_libdw=no}
   : ${with_ncbicrypt=no}
   : ${with_pcre=no} # Too much variation across distributions.
   : ${with_sse42=no}
   AC_DEFINE(NCBI_BIN_RELEASE, 1,
             [Define to 1 when building binaries for public release.])
fi

case "$with_strip:$with_symbols" in
   yes:yes )
      AC_MSG_ERROR([incompatible options: --with-strip but --with-symbols])
      ;;
   yes:* )
      with_symbols=no
      ;;
esac

if test "$with_debug" = no; then
    : ${with_symbols=no}
    : ${with_optimization=yes}
    if test "${with_max_debug-no}" != no; then
       AC_MSG_ERROR([incompatible options: --without-debug but --with-max-debug])
    fi
else
    : ${with_symbols=yes}
    : ${with_optimization=no}
fi

if test "$with_openmp" = yes; then
   if test "$with_mt" = no; then
      AC_MSG_ERROR([incompatible options: --without-mt but --with-openmp])
   fi
   : ${with_mt=yes} 
fi

case "$with_downloaded_vdb:$with_vdb" in
   yes:no )
      AC_MSG_ERROR([incompatible options: --without-vdb but
                    --with-downloaded-vdb])
      ;;
   yes: )
      with_vdb=yes
      ;;
esac

case "$with_static_vdb:$with_vdb" in
   yes:no )
      AC_MSG_ERROR([incompatible options: --without-vdb but --with-static-vdb])
      ;;
   yes: )
      with_vdb=yes
      ;;
   :* )
      with_static_vdb=$with_bin_release
      ;;
esac

case "$with_static_gnutls:$with_gnutls" in
   yes:no )
      AC_MSG_ERROR([incompatible options: --without-gnutls but --with-static-gnutls])
      ;;
   yes: )
      with_gnutls=yes
      ;;
   :yes )
      with_static_gnutls=$with_bin_release
      ;;
esac

m4_foreach(OPT, [serial,objects,dbapi,algo],
   [if test -n "[$with_]OPT"; then
       AC_MSG_WARN([--with(out)-]OPT[ is deprecated])
       AC_MSG_WARN([please simply pass an appropriate project list])
    fi
   ])

#### Check for special options
if test "$with_extra_action" = "yes" ; then
   AC_MSG_ERROR([--with-extra-action must have a value after =])
fi
if test "$with_extra_action" = "no" ; then
   AC_MSG_ERROR([--without-extra-action is not allowed])
fi

case "$with_projects" in
 ""|yes)
     if test -r projects; then
        AC_MSG_NOTICE([using default projects file "projects".])
        with_projects=projects
        AC_SUBST(PROJECTS, "\$(top_srcdir)/projects")
     else
        AC_SUBST(PROJECTS, "")
        if test -f projects; then
           AC_MSG_WARN([default projects file "projects" is unreadable.])
        elif test -h projects; then
           AC_MSG_WARN([default projects file "projects" is a dangling link.])
        fi
     fi
     ;;
 no) with_projects="" ;  AC_SUBST(PROJECTS, "") ;;
 /*) AC_SUBST(PROJECTS, $with_projects) ;;
 * ) AC_SUBST(PROJECTS, "\$(top_srcdir)/$with_projects") ;;
esac

if test -n "$with_projects"; then
   case "$with_projects" in
      /* ) abs_projects=$with_projects         ;;
      yes) abs_projects=$srcdir/projects       ;;
      *  ) abs_projects=$srcdir/$with_projects ;;
   esac
   test -r "$abs_projects"  ||  \
      AC_MSG_ERROR([unable to read requested projects file "$abs_projects".])
fi

# Check for custom optimization flags before potentially going with defaults.
skip_fast_flags=no
if test -z "${DEF_FAST_FLAGS}${FAST_CXXFLAGS}"; then
   case " $CFLAGS $CXXFLAGS" in
      *\ -O* | *\ -xO* ) skip_fast_flags=yes ;;
   esac
fi
# Generally save any originally specified flags.
USER_CFLAGS=$CFLAGS
USER_CXXFLAGS=$CXXFLAGS
USER_LDFLAGS=$LDFLAGS

want_cxx20=no
want_c2x=no
if test -n "$with_experimental"; then
   NCBI_C_PATH_TAGS="/ncbi.gi64 .gi64"
   want_gi32=no
   want_gi64=no
   for x in `echo $with_experimental | tr , ' '`; do
      case "$x" in
         ChaosMonkey )
            AC_DEFINE(NCBI_MONKEY, 1,
               [Define to 1 to enable "ChaosMonkey" failure testing.])
            NCBI_FEATURE(ChaosMonkey)
            ;;
         Int4GI )
            AC_DEFINE(NCBI_INT4_GI, 1,
               [Define to 1 to use a simple 32-bit type for GI numbers.])
            NCBI_C_PATH_TAGS=
            NCBI_FEATURE(Int4GI)
            want_gi32=yes
            ;;
         Int8GI )
            AC_DEFINE(NCBI_INT8_GI, 1,
               [Define to 1 to use a simple 64-bit type for GI numbers.])
            NCBI_FEATURE(Int8GI)
            want_gi64=yes
            ;;
         StrictGI )
            AC_DEFINE(NCBI_STRICT_GI, 1,
               [Define to 1 to use a strict 64-bit type for GI numbers.])
            NCBI_FEATURE(Int8GI)
            NCBI_FEATURE(StrictGI)
            want_gi64=yes
            ;;
         PSGLoader )
            # Contingent on third-party library availability
            ;;
         BM64 )
            AC_DEFINE(BM64ADDR, 1, [Define to 1 to use 64-bit bitset indices.])
            NCBI_FEATURE(BM64)
            ;;
         C++20 )
            want_cxx20=yes
            ;;
         C2X )
            want_c2x=yes
            ;;
         * )
            AC_MSG_ERROR([unrecognized experimental feature "$x".])
            ;;
      esac
   done
   if test "$want_gi32:$want_gi64" = "yes:yes"; then
      AC_MSG_ERROR([Incompatible experimental features Int8GI (and/or StrictGI) and Int4GI.])
   fi
fi

#### Always define this
AC_DEFINE(NCBI_CXX_TOOLKIT, 1, [This is the NCBI C++ Toolkit.])

AC_MSG_CHECKING([TeamCity build number])
if test -n "$TEAMCITY_VERSION" -a -n "$BUILD_NUMBER"; then
   AC_MSG_RESULT($BUILD_NUMBER)
   NCBI_TEAMCITY_BUILD_NUMBER=$BUILD_NUMBER
   NCBI_TEAMCITY_PROJECT_NAME=$TEAMCITY_PROJECT_NAME
   NCBI_TEAMCITY_BUILDCONF_NAME=$TEAMCITY_BUILDCONF_NAME
   NCBI_TEAMCITY_BUILD_ID=`sed -ne 's/^teamcity\.build\.id=//p' \
                           $TEAMCITY_BUILD_PROPERTIES_FILE`
else
   AC_MSG_RESULT(none)
   NCBI_TEAMCITY_BUILD_NUMBER=0
fi

AC_MSG_CHECKING([VCS revision])
gitrev=`git -C "$srcdir" log -1 --format=%h 2>/dev/null`
svnrev=`svn info "$srcdir" 2>/dev/null | sed -ne 's/^Revision: //p'`
if test -n "$svnrev"; then
   NCBI_SUBVERSION_REVISION=$svnrev
fi
if test -n "$gitrev"; then
   AC_MSG_RESULT([$gitrev (Git)])
   NCBI_REVISION=$gitrev
   : ${NCBI_SUBVERSION_REVISION=0}
elif test -n "$svnrev"; then
   AC_MSG_RESULT([$svnrev (Subversion)])
   NCBI_SUBVERSION_REVISION=$svnrev
   NCBI_REVISION=$svnrev
elif test -n "$NCBI_SUBVERSION_REVISION"; then
   AC_MSG_RESULT($NCBI_SUBVERSION_REVISION)
   NCBI_REVISION=$NCBI_SUBVERSION_REVISION
else
   AC_MSG_RESULT(unknown)
   NCBI_SUBVERSION_REVISION=0
fi
if test -n "$NCBI_REVISION"; then
   # The overall presence or absence of revision info should be stable,
   # even if the specific revision ID evolves.
   AC_DEFINE(HAVE_NCBI_REVISION, 1,
      [Define to 1 if an overall revision ID is available.])
fi

AC_MSG_CHECKING([NCBI stable components' version])
scver=`svn info "$srcdir/src/build-system" 2>/dev/null |
 sed -ne ['s,^URL: .*/production/components/[^/]*/\([1-9][0-9]*\)\..*,\1,p']`
if test -n "$scver"; then
   AC_MSG_RESULT($scver)
   NCBI_SC_VERSION=$scver
elif test -n "$NCBI_SC_VERSION"; then
   AC_MSG_RESULT($NCBI_SC_VERSION)
else
   AC_MSG_RESULT(unknown)
   NCBI_SC_VERSION=0
fi

AC_DEFINE(HAVE_COMMON_NCBI_BUILD_VER_H, 1,
   [Define to 1 if you have the <common/ncbi_build_ver.h> header file.])

#### Get the running host's properties
AC_CONFIG_AUX_DIR(src/build-system)
AC_CANONICAL_HOST
AC_DEFINE_UNQUOTED(HOST,        "$host",        [Full GNU-style system type])
AC_DEFINE_UNQUOTED(HOST_CPU,    "$host_cpu",    [CPU type only])
AC_DEFINE_UNQUOTED(HOST_VENDOR, "$host_vendor", [System vendor only])
AC_DEFINE_UNQUOTED(HOST_OS,     "$host_os",     [System OS only])


#### Make some provisions for traditional operation
AC_PROG_INSTALL

#### Help ICC get off the ground ASAP.
case "/$CXX" in
   */icpc )
      if test -d /opt/ncbi/gcc -o -d /usr/local/gcc; then
         case "`$CXX -dumpversion`:$host_cpu" in
            *:i?86)           v=4.4.5 ;;
            ?.* | 1[[01]].* ) v=4.0.1 ;;
            1[[23]].*)        v=4.4.2 ;;
            1[[456]].*)       v=4.9.3 ;;
            17.*) v=7.3.0; CPPFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 $CPPFLAGS" ;;
            *)                v=7.3.0 ;;
         esac
         for gcc in /opt/ncbi/gcc/$v/bin/gcc /usr/local/gcc/$v/bin/gcc; do
            if test -x $gcc; then
               CC="$CC -gcc-name=$gcc"
               CXX="$CXX -gcc-name=$gcc"
               case $gcc in
                  /opt/* )
                     LDFLAGS="-Wl,-rpath,/opt/ncbi/gcc/$v/lib64 $LDFLAGS"
                     ;;
                  /usr/* )
                     LDFLAGS="-Wl,-rpath,/usr/lib64/gcc-$v $LDFLAGS"
                     ;;
               esac
               break
            fi
         done
      fi
      ;;
   */icpx )
      case "$host_cpu" in
         i?86   ) intel_cpu_name=ia32      ;;
         x86_64 ) intel_cpu_name=intel64   ;;
         *      ) intel_cpu_name=$host_cpu ;;
      esac

      set $CXX
      x_CXX="`type $1 | sed 's/.* \([^ ]*\)$/\1/'`"
      if test ! -x "$x_CXX" ; then
         x_CXX="`which $1 2>/dev/null`"
      fi

      compiler_root=${x_CXX%/bin/*}
      icc_libdir=$compiler_root/compiler/lib/$intel_cpu_name
      LDFLAGS="-L$icc_libdir -Wl,-rpath,$icc_libdir -lintlc $LDFLAGS"
      ;;
esac

#### Don't let Clang pick up old (pre-C++14) system standard
#### library installations on Linux.
case "$host_os:/$CXX" in
   linux*:*/clang* | */icpx )
      case "`$CXX --version`" in
         *version\ 3.* )
            gccver=5.3.0
            CPPFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 $CPPFLAGS"
            ;;
         *version\ ?.* | *version\ 1[[0-3]].* )
            gccver=7.3.0
            ;;
         * )
            gccver=12.2.0
            ;;
      esac
      gccdir=/opt/ncbi/gcc/$gccver
      if test -d $gccdir; then
         # CPPFLAGS="--gcc-toolchain=$gccdir $CPPFLAGS"
         # LDFLAGS="--gcc-toolchain=$gccdir $LDFLAGS"
         for d in `$gccdir/bin/g++ -v -E -x c++ $ARCH_CFLAGS $ARCH_CPPFLAGS - \
                   </dev/null 2>&1 | fgrep 'include/c++' | tac`; do
            NCBI_FIX_DIR(d)
            # We don't use a dedicated CXXCPPFLAGS variable, but sticking
            # with -isystem rather than -cxx-isystem avoids spurious
            # warnings when also using ccache or distcc, and should still
            # be safe in practice.  (The three libstdc++ headers that have
            # the same names as system headers all arrange to include
            # those headers via #include_next, and to conditionalize any
            # C++ declarations on compiling as actual C++.)
            CPPFLAGS="-isystem $d $CPPFLAGS"
         done
         CPPFLAGS="-nostdinc++ $CPPFLAGS"
         libstdcxx=`$gccdir/bin/g++ --print-file-name=libstdc++.a`
         d=`dirname $libstdcxx`
         NCBI_FIX_DIR(d)         
         LDFLAGS="-L$d -Wl,-rpath,$d $LDFLAGS"
         crtbegin=`$gccdir/bin/g++ --print-file-name=crtbegin.o`
         d=`dirname $crtbegin`
         NCBI_FIX_DIR(d)         
         LDFLAGS="-L$d -B$d $LDFLAGS"
      fi
      ;;
esac

#### C and C++ compilers
AC_LANG(C++)
AC_PROG_CC
ac_build_objext=$ac_objext
AS_UNSET([ac_cv_c_compiler_gnu])
AX_PROG_CC_FOR_BUILD
AC_PROG_CXX


#### Detect Insure++, and attempt to find the real compiler.
case "$CXX" in
   insure* | */insure*)
      psrcdump=`echo "$CXX" | sed -e 's/insure.*/psrcdump/'`
      real_CXX=`$psrcdump -t insure++ | sed -ne 's/^Compiler \(.*\)/\1/p'`
      real_dir=`$psrcdump -t insure++ | sed -ne 's/^Compilerinstalldir \(.*\)/\1/p'`
      test -n "$real_dir" && test -x "$real_dir/$real_CXX" && \
        real_CXX="$real_dir/$real_CXX"
      case "$real_CXX" in
          *gcc* ) LIBS="$LIBS -lstdc++"
      esac
      ;;
   *)
      real_CXX=$CXX
      ;;
esac


#### Detect KCC compiler
if test "$GCC" != "yes" ; then
   touch kcc_test.cpp
   kcc_ver="`$real_CXX -V -c kcc_test.cpp 2>&1 | grep '^KAI '`"
   kcc_license="`$real_CXX -V -c kcc_test.cpp 2>&1 | grep -v '^KAI '`"
   rm -f kcc_test.cpp kcc_test.o
   case "$kcc_ver" in
      KAI* )  KCC="yes" ;;
   esac
fi


#### Detect ICC compiler (newer versions of which configure can mis-ID as GCC)
if test "$KCC" != "yes"; then
   icc_ver="`$real_CXX -V 2>&1 | grep '^Intel(R) '`"
   icc_license="`$real_CXX -c 2>&1 | grep '^icc: NOTE: The evaluation period for this product ends on '`"
   case "$icc_ver" in
      Intel*C*Compiler* )  ICC="yes"; GCC="no" ;;
   esac
fi


#### Detect Clang compiler (which also masquerades as GCC)
if test "$KCC" != "yes"  -a  "$ICC" != yes; then
   clang_ver="`$real_CXX -v 2>&1 | grep clang | grep ' version '`"
   if test -n "$clang_ver"; then
      Clang=yes
      GCC=no
   fi
fi


#### Detect IBM VisualAge compiler
if test "$GCC" != "yes"  -a  "$KCC" != "yes"  -a  "$ICC" != "yes" \
  -a  "$Clang" != "yes" ; then
   vac_ver="`$real_CXX -qversion 2>&1`"
   case "$vac_ver" in
      *AIX* ) VAC="yes" ;;
   esac
fi


#### Detect Compaq compiler
if test "$GCC" != "yes"  -a  "$KCC" != "yes"  -a  "$ICC" != "yes" \
  -a  "$Clang" != "yes"  -a  "$VAC" != "yes"; then
   ccc_ver="`$real_CXX -V 2>&1 | grep '^Compaq C++ V'`"
   case "$ccc_ver" in
      *Compaq* ) CCC="yes" ;;
   esac
fi


#### Detect Cray compiler
if test "$GCC" != "yes"  -a  "$KCC" != "yes"  -a  "$ICC" != "yes" \
  -a  "$Clang" != "yes"  -a  "$VAC" != "yes" -a  "$CCC" != "yes"; then
   cce_ver="`$real_CXX -V 2>&1 | grep '^Cray'`"
   case "$cce_ver" in
      *Cray* ) CCE="yes" ;;
   esac
fi


#### Detect supported compilers
compiler=
compiler_ver=
ncbi_compiler="UNKNOWN"
ncbi_compiler_ver="0"

if test "$GCC" = "yes" ; then
   compiler_ver="`$real_CXX -dumpfullversion 2>/dev/null \
       || $real_CXX -dumpversion 2>&1`"
   case "$compiler_ver" in
     *.*.* ) ;;
     * )
       fullversion="`$real_CXX --version | \
           sed -ne '1s/.*) \([[1-9]][[0-9.]]*\).*/\1/p'`"
       case "$fullversion" in
         "$compiler_ver".* ) compiler_ver=$fullversion ;;
       esac
       ;;
   esac
   compiler="GCC"
   ncbi_compiler="GCC"
   ncbi_compiler_ver="$compiler_ver"
   NCBI_FEATURE(GCC)
elif test "$KCC" = "yes" ; then
   compiler_ver="$kcc_ver"
   compiler="KCC"
   ncbi_compiler="KCC"
   ncbi_compiler_ver="`echo $kcc_ver | sed 's%^KAI .*C[[+]][[+]] \([[0-9.]]*\).*%\1%'`"
   NCBI_FEATURE(KCC)
elif test "$ICC" = "yes" ; then
   compiler_ver="$icc_ver"
   compiler="ICC"
   ncbi_compiler="ICC"
   ncbi_compiler_ver="`echo $icc_ver | sed 's%.*Version \([[0-9.]]*\).*%\1%'`"
   NCBI_FEATURE(ICC)
elif test "$Clang" = "yes" ; then
   compiler_ver="$clang_ver"
   case "$compiler_ver" in
      *Apple* )
         compiler=AppleClang
         ncbi_compiler=APPLE_CLANG
         NCBI_FEATURE(AppleClang)
         ;;
      * )
         compiler=LLVMClang
         ncbi_compiler=LLVM_CLANG
         NCBI_FEATURE(LLVMClang)
         ;;
   esac
   ncbi_compiler_ver="`echo $clang_ver | sed 's%.*version \([[0-9.]]*\).*%\1%'`"
   NCBI_FEATURE(Clang)
elif test "$VAC" = "yes" ; then
   compiler_ver="$vac_ver"
   compiler="VisualAge"
   ncbi_compiler="VISUALAGE"
   ncbi_compiler_ver="`echo $vac_ver | sed 's%.*[[Vv]]ersion:* 0*\([[0-9.]]*\).*%\1%'`"
   NCBI_FEATURE(VisualAge)
elif test "$CCC" = "yes" ; then
   compiler_ver="$ccc_ver"
   compiler=Compaq
   ncbi_compiler="COMPAQ"
   ncbi_compiler_ver="`echo $ccc_ver | sed 's%.*C[[+]][[+]] V\([[0-9.]]*\).*%\1%'`"
   NCBI_FEATURE(CompaqCompiler)
elif test "$CCE" = "yes" ; then
   compiler_ver="$cce_ver"
   compiler="Cray"
   ncbi_compiler="CRAY"
   ncbi_compiler_ver="`echo $cce_ver | sed 's%.*Version \([[0-9.]]*\).*%\1%'`"
   NCBI_FEATURE(Cray)
else
   case "$host_os" in
    solaris* )
      compiler_ver="`$real_CXX -V 2>&1`"
      case "$compiler_ver" in
        *WorkShop*Compilers*5\.0 )
          compiler="WorkShop5"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.0" ;;
        *Sun*WorkShop*6*5\.1* )
          compiler="WorkShop51"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.1" ;;
        *Sun*WorkShop*6*5\.2* )
          compiler="WorkShop52"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.2" ;;
        *Sun*WorkShop*6*5\.3* )
          compiler="WorkShop53"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.3" ;;
        *Forte*7*5\.4* )
          compiler="WorkShop54"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.4" ;;
        *Sun*C*5\.5* )
          compiler="WorkShop55"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.5" ;;
        *Sun*C*5\.8* )
          compiler="WorkShop58"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.8" ;;
        *Sun*C*5\.9* )
          compiler="WorkShop59"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.9" ;;
        *Sun*C*5\.10* )
          compiler="WorkShop510"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.10" ;;
        *Sun*C*5\.11* )
          compiler="WorkShop511"
          ncbi_compiler="WORKSHOP"
          ncbi_compiler_ver="5.11" ;;
      esac
      NCBI_FEATURE(WorkShop)
      ;;

    irix* )
      compiler_ver="`$real_CXX -version 2>&1`"
      case "$compiler_ver" in
        MIPSpro*Compilers:*Version*7\.3* )
          compiler="MIPSpro73"
          ncbi_compiler="MIPSPRO"
          ncbi_compiler_ver="7.3"
          NCBI_FEATURE(MIPSpro)
          ;;
      esac
      ;;

    cygwin* )
      case "$real_CXX" in
        *cl\.exe* | cl)
          compiler="MSVC"
          ncbi_compiler="MSVC"
          ncbi_compiler_ver="6.0"
          NCBI_FEATURE(MSVC)
          ;;
      esac
      ;;
   esac
fi

changequote(, )dnl
#ncbi_compiler_ver="`echo $ncbi_compiler_ver | sed 's%\([0-9]\)\.\([0-9]\)\.\([0-9]\).*%\1\2\3%; s%\([0-9]\)\.\([0-9][0-9]*\).*%\1\2%; s%^\([0-9][0-9]\)$%\10%; s%^\([0-9]\)$%\100%'`"
case "$compiler:$ncbi_compiler_ver" in
    WorkShop*:?.?? )   ncbi_compiler_sed='s/\([0-9]\)\.\([0-9][0-9]\)/\1\20/' ;;
    WorkShop*:[6-9].?) ncbi_compiler_sed='s/\([0-9]\)\.\([0-9\)/\10\20/' ;;
    [GI]CC:??.? ) ncbi_compiler_sed='s/\([0-9][0-9]\)\.\([0-9]\)/\1\20/' ;;
    GCC:??.?.? | ICC:??.?.? | ICC:??.?.?.* | *Clang:??.?.? )
       ncbi_compiler_sed='s/\([0-9][0-9]\)\.\([0-9]\)\.\([0-9]\).*/\1\2\3/' ;;
    GCC:?? )    ncbi_compiler_sed='s/\([0-9][0-9]\)/\100/' ;;
    ICC:20??.?.? | ICC:20??.?.?.* )
       ncbi_compiler_sed='s/20\([0-9][0-9]\)\.\([0-9]\)\.\([0-9]\).*/\1\2\3/' ;;
    *:?.?.?)    ncbi_compiler_sed='s/\([0-9]\)\.\([0-9]\)\.\([0-9]\)/\1\2\3/' ;;
    *:?.??*)    ncbi_compiler_sed='s/\([0-9]\)\.\([0-9][0-9]\).*/\1\2/' ;;
    *:?.?)      ncbi_compiler_sed='s/\([0-9]\).\([0-9]\)/\1\20/' ;;
    *:?)        ncbi_compiler_sed='s/\([0-9]\)/\100/' ;;
changequote([, ])dnl
    *)    AC_MSG_ERROR([Do not know how to parse $compiler version number $ncbi_compiler_ver]) ;;
esac
ncbi_compiler_ver=`echo $ncbi_compiler_ver | sed "$ncbi_compiler_sed"`
compiler_version=$ncbi_compiler_ver

# Possible values of NCBI_COMPILER_$ncbi_compiler, since acconfig.h is obsolete
if false; then
   AC_DEFINE(NCBI_COMPILER_GCC,       1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_KCC,       1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_ICC,       1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_APPLE_CLANG,1,[Compiler name])
   AC_DEFINE(NCBI_COMPILER_LLVM_CLANG,1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_WORKSHOP,  1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_MIPSPRO,   1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_VISUALAGE, 1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_COMPAQ,    1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_CRAY,      1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_MSVC,      1, [Compiler name])
   AC_DEFINE(NCBI_COMPILER_UNKNOWN,   1, [Compiler name])
fi

AC_DEFINE_UNQUOTED(NCBI_COMPILER, "$ncbi_compiler", [Compiler name])
AC_DEFINE_UNQUOTED(NCBI_COMPILER_$ncbi_compiler, 1, [Compiler name])
AC_DEFINE_UNQUOTED(NCBI_COMPILER_VERSION, $ncbi_compiler_ver,
                   [Compiler version as three- or four-digit integer])


#### Additional check for pre-defined compilers
case "$compiler:$compiler_version" in
  MSVC:* )
    if test -z "$NCBI_COMPILER" ; then
       echo
       echo "Compiler \"${compiler}\" requires a special tuning, so you"
       echo "better use a special shell script located in \"compilers/*.sh\"!"
       NCBI_CAUTION([Do you still want to proceed (at your own risk)?])
       echo
    fi ;;
esac


#### Use full path to the compiler, if possible
changequote(, )dnl

set $CC
x_CC="`type $1 | sed 's/.* \([^ ]*\)$/\1/'`"
if test ! -x "$x_CC" ; then
  x_CC="`which $1  2>/dev/null`"
fi

if test -x "$x_CC" ; then
  shift
  CC="$x_CC $*"
  echo "adjusted C   compiler: $CC"
fi
CC_PATH="`dirname $x_CC`"
x_CC=

set $CXX
x_CXX="`type $1 | sed 's/.* \([^ ]*\)$/\1/'`"
if test ! -x "$x_CXX" ; then
  x_CXX="`which $1  2>/dev/null`"
fi

if test -x "$x_CXX" ; then
  shift
  CXX="$x_CXX $*"
  echo "adjusted C++ compiler: $CXX"
fi
CXX_PATH="`dirname $x_CXX`"

if test "$with_static_exe" = "yes"; then
   C_LINK='$(top_srcdir)/scripts/common/impl/favor-static $(CC)'
   LINK='$(top_srcdir)/scripts/common/impl/favor-static $(CXX)'
else
   C_LINK='$(CC)'
   LINK='$(CXX)'
fi

### Which of these is better?
#compiler_root=`dirname CXX_PATH`
compiler_root=`echo $x_CXX | sed -ne 's:\(.*\)[/\\]bin[/\\].*:\1:p'`
x_CXX=

changequote([, ])dnl


#### Multi-Thread safety
# Historically off by default; respect that when reconfiguring old builds.
if test -z "$with_mt" -a -f "$NCBI_OLD_STATUS_DIR/-MT.enabled"; then
    with_mt=no
fi

if test "$with_mt" != "no" ; then
   with_mt=yes
   case "$host_os:$compiler" in
    darwin* | irix* | cygwin* | *:Cray ) ;;
    solaris*:WorkShop*       )  : ${MT_FLAG:="-mt"} ;;
    solaris*:GCC             )  : ${MT_FLAG:="-pthreads"} ;;
    *:KCC                    )  : ${MT_FLAG:="--thread_safe"} ;;
    *:Compaq | *:GCC | *:ICC | *Clang )
                                : ${MT_FLAG:="-pthread"} ;;
    *:VisualAge              )  : ${MT_FLAG:="-qthreaded"} ;;
    * )
       msg="Do not know how to build MT-safe with compiler $CXX $compiler_ver"
       case "$with_mt" in
          yes ) AC_MSG_ERROR([$msg]) ;;
          ''  ) AC_MSG_WARN([$msg]); with_mt=no ;;
       esac
       ;;
   esac
fi

case "$host_os:$compiler" in
  solaris2.10:GCC ) : ${THREAD_LIBS:="-lposix4"} ;;
  solaris*        ) : ${THREAD_LIBS:="-lpthread -lposix4"} ;;
  freebsd*        ) : ${THREAD_LIBS:="-pthread"} ;; # for LMDB in ST builds
  *               ) : ${THREAD_LIBS:="-lpthread"} ;;
esac

if test "$with_mt" != "no" ; then
   CPPFLAGS="$CPPFLAGS -D_MT -D_REENTRANT -D_THREAD_SAFE"
   LIBS="$LIBS $THREAD_LIBS"
   case "$host_os:$compiler" in
     solaris2.??:* | solaris*:GCC | *:Compaq | irix* | aix* | darwin* | cygwin*)
        NCBIATOMIC_LIB=
        ;;
     *:GCC | *:ICC | *Clang | linux*:KCC )
        case "$host_cpu" in
           i?86 | powerpc* | ppc* | x86_64 | sparc* | aarch64 | arm* )
              NCBIATOMIC_LIB=
              ;;
           * ) NCBIATOMIC_LIB=xncbi ;;
        esac
        ;;
     *:WorkShop* | solaris*:KCC )
        NCBIATOMIC_LIB=xncbi
        ncbicntr="ncbicntr_workshop ncbiatomic_workshop"
        ;;
     * ) NCBIATOMIC_LIB=xncbi ;;
   esac
   case "$compiler" in
      GCC | LLVMClang ) # Not yet AppleClang, as of version 11.
         : ${OPENMP_FLAGS=-fopenmp}
         ;;
      ICC )
         : ${OPENMP_FLAGS=-qopenmp -qopenmp-link=static}
         ;;
      WorkShop* )
         : ${OPENMP_FLAGS=-xopenmp=parallel}
         ;;
   esac
   if test "$with_openmp" = yes; then
      MT_FLAG="$MT_FLAG $OPENMP_FLAGS"
      OPENMP_FLAGS=
   fi
   mt_sfx="MT"
   NCBI_FEATURE(MT)
else
   CPPFLAGS="$CPPFLAGS -DNCBI_WITHOUT_MT"
   MT_FLAG=
   NCBIATOMIC_LIB=
   OPENMP_FLAGS=
   mt_sfx=""
fi
MT_SFX="${mt_sfx}"
AC_SUBST(MT_SFX)

CFLAGS="$MT_FLAG $CFLAGS"
CXXFLAGS="$MT_FLAG $CXXFLAGS"
LDFLAGS="$MT_FLAG $LDFLAGS"

APP_LDFLAGS=
DLL_LDFLAGS=

#### Provide default environment setup for known platforms/compilers
DEPFLAGS="-M"
DEPFLAGS_POST="" # Needed for VisualAge
OBJCXX_CXXFLAGS=
OBJCXX_LIBS=
case "$host_os:$compiler:$compiler_version" in
 solaris2\.6:GCC:* )
   echo "GCC compiler is not supported for:  $host"
   compiler=
   ;;

 solaris*:GCC:* )
   STRIP="@:"
   ;;

 linux*:ICC:??? | linux*:ICC:1??? )
   # -we70: "incomplete type is not allowed" should be an error, not a warning!
   # -we10159: So should "invalid argument for option '-std'", to allow for
   #           effective configure-time probing.
   # -wd2651: Suppress spurious "attribute does not apply to any entity"
   #          when deprecating enum values (via NCBI_STD_DEPRECATED).
   CFLAGS="-we70 -we10159 $CFLAGS"
   CXXFLAGS="-we70 -we10159 -wd2651 $CXXFLAGS"
   MATH_LIBS=-Wl,-lm # avoid static libimf in shared libs
   ;;

 linux*:GCC:* )
    if test -r $srcdir/src/build-system/config.site.ncbi && test -d "$NCBI"
    then
       case "$compiler_version" in
          5?? ) CPPFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 $CPPFLAGS" ;;
       esac
    fi
    ;;

 irix*:GCC:* )
   if test "$with_debug" != "no" ; then
      LDFLAGS="-LD_LAYOUT:lgot_buffer=32 $LDFLAGS"
   fi
   ;;

 solaris*:WorkShop* )
   CPPFLAGS="-D__EXTENSIONS__ $CPPFLAGS"
   CXXFLAGS="+w +w2 $CXXFLAGS"
   DEPFLAGS="-xM1"
   LDFLAGS="-xildoff $LDFLAGS"
   AR=${AR:="$CXX $MT_FLAG -xar -o"}
   STRIP="@:"
   if test "$with_symbols" = "no" -a "$with_profiling" != "yes" \
      -a "$with_strip" = "yes" ; then
      LDFLAGS="-s $LDFLAGS"
   fi
   # Recent versions default to DWARF, yielding much larger executables in
   # debug configurations; insist on STABS when the choice exists, even for
   # versions that already default to it.
   case "$with_symbols:$compiler" in
      no:* | *:WorkShop5[[0-4]] ) ;;
      * )
         CFLAGS="-xdebugformat=stabs $CFLAGS"
         CXXFLAGS="-xdebugformat=stabs $CXXFLAGS"
         ;;
   esac
   CXX_FILTER="2>&1 | \$(top_srcdir)/compilers/unix/cxx_filter.WorkShop.sh"
   LINK_FILTER="$CXX_FILTER"
   AR_FILTER="$CXX_FILTER"
   serial_ws50_rtti_kludge="rtti"
   ;;

 irix*:MIPSpro73:* )
   COMMON_FLAGS="-fullwarn -brief_diagnostics -use_readonly_const -G0 -rdata_shared"
   # Warnings we disable (messages courtesy of "gettxt cc.cat.m:N")
   # 1107: A signed bit field has a length of 1 bit.
   # 1169: External/internal linkage conflicts with a previous declaration.
   # 1209: The controlling expression is constant. [while (0) et al.]
   # 1424: The %n1 is not used in declaring the argument types of %n2.
   # 1429: The type "long long" is nonstandard.
   # 1460: Function %n is redeclared "inline" after being called.
   # 1521: A nonstandard preprocessing directive is used.
   CFLAGS="$COMMON_FLAGS -woff 1209 $CFLAGS"
   CXXFLAGS="$COMMON_FLAGS -ansiW -ptused -FE:eliminate_duplicate_inline_copies -FE:template_in_elf_section -no_auto_include -LANG:std -LANG:ansi-for-init-scope -woff 1460,1521,1429,1169,1209,1107,1424 $CXXFLAGS"
   : ${CXXCPP:="$CXX -E -LANG:std"}
   LDFLAGS="-LANG:std -G0 -FE:eliminate_duplicate_inline_copies -FE:template_in_elf_section $LDFLAGS"
   CPPFLAGS="-D__LONGLONG $CPPFLAGS"
   CXX_FILTER="2>&1 | \$(top_srcdir)/compilers/unix/cxx_filter.$compiler.sh"
   ;;

 cygwin*:GCC:* )
   CPPFLAGS="-D_GLIBCXX_USE_C99 $CPPFLAGS"
   CXXFLAGS="-Wa,-mbig-obj $CXXFLAGS"
   with_dll="no"
   # : ${NETWORK_LIBS:="-lws2_32"}
   CONF_exe_ext=".exe"
   ;;

 cygwin*:MSVC:* )
   with_dll="no"
   CFLAGS="/W4 /Od /Zi /DEBUG /D_DEBUG"
   CXXFLAGS="/W4 /Od /Zi /DEBUG /D_DEBUG"
   CPPFLAGS="/nologo $CPPFLAGS"
   LDFLAGS="/DEBUG"
   AR="lib.exe"
   RANLIB=":"
   STRIP="@:"
   CONF_obj_ext=".obj"
   CONF_lib_ext=".lib"
   CONF_dll_ext=".dll"
   CONF_lib_l_ext=".lib"
   CONF_lib_pre=" "
   CONF_lib_l_pre=" "
   CONF_exe_ext=".exe"
   CONF_f_compile="/c "
   CONF_f_outobj="/Fo"
   CONF_f_outlib="/OUT:"
   CONF_f_libpath="/LIBPATH:"
   CONF_f_outexe="/OUT:"
   script_shell=""
   make_shell=""
   ;;

 *:VisualAge:* )
   # 1506-1108 (I) The use of keyword '__attribute__' is non-portable.
   CFLAGS="-qlanglvl=extc99 -qsuppress=1506-1108 $CFLAGS"
   # 1540-1663 (W) Incorrect assignment of a restrict qualified pointer.
   CXXFLAGS="-qrtti=all -qsuppress=1540-1663 $CXXFLAGS"
   DEPFLAGS="-E -M"
   DEPFLAGS_POST='>/dev/null 2>&1; (cat $*.u; rm -f $*.u)'
   ;;

 *:Compaq:* )
   CPPFLAGS="-D__USE_STD_IOSTREAM $CPPFLAGS"
   CXXFLAGS="-tweak -nocompress -distinguish_nested_enums $CXXFLAGS"
   DEPFLAGS="$DEPFLAGS -distinguish_nested_enums"
   case "$host_os" in
      osf*)
        # Suppress link warnings; otherwise, we get "weak symbol multiply
        # defined" all over the place.
        LDFLAGS="-Wl,-S $LDFLAGS"
        # The linker sometimes needs a LOT of memory.
        LINK="ulimit -d \`ulimit -H -d\` && $LINK"
        ;;
   esac
   ;;

 darwin*:GCC:* | darwin*:*Clang:* )
   case `uname -m` in
      *64 ) : ${with_64=yes} ;;
      *   ) : ${with_64=no}  ;;
   esac
   # Per <https://fink.sourceforge.net/doc/porting/shared.php>, it was
   # historically necessary to build plugins as Mach-O bundles rather than
   # dynamic libraries.  That's not such a big deal on modern Mac OS X
   # versions, so the Toolkit now defaults to building only the latter.
   CONF_dll_ext=".dylib"
   if test "$with_bundles" = yes; then
      CONF_loadable_ext=".so"
   else
      CONF_loadable_ext=".dylib"
   fi
   if test "$compiler" = AppleClang \
      ||  ("$compiler" = GCC  &&  $CXX -v 2>&1 | grep -q Apple) ; then
      CFLAGS="-fpascal-strings $CFLAGS"
      CXXFLAGS="-fpascal-strings $CXXFLAGS"
      if test "$compiler" = AppleClang; then
         try_old_sdks=no
      else
         try_old_sdks=$with_ncbi_public
         CXXFLAGS="-fno-permissive $CXXFLAGS"
      fi
      # -flat_namespace is necessary for proper handling of shared libraries
      # that don't themselves link against all their dependencies.
      LDFLAGS="-flat_namespace -headerpad_max_install_names $LDFLAGS"

      if test "$try_old_sdks" = yes; then
         sdks='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk'
         case "$host_os" in
            darwin?.* | darwin10.* ) # Mac OS X 10.6.x or older
               TARGET='-mmacosx-version-min=10.5'
               sdks="/Developer/SDKs/MacOSX10.6.sdk"
               ;;
            * )
               TARGET='-mmacosx-version-min=10.7'
               ;;
         esac
         for sdk in $sdks; do
            if test -d "$sdk"; then 
               TARGET="-isysroot $sdk $TARGET"
               break
            fi
         done
         CC="$CC $TARGET"
         CXX="$CXX $TARGET"
      fi
   else
      LDFLAGS="-Wl,-flat_namespace -Wl,-headerpad_max_install_names $LDFLAGS"
   fi
   if test -f /usr/include/dlfcn.h; then
      # may be able to do without /sw, so ignore it by default
      :
   elif test -f /sw/include/dlfcn.h; then
      CPPFLAGS="-I/sw/include $CPPFLAGS"
      LDFLAGS="-L/sw/lib $LDFLAGS"
   else
      AC_MSG_WARN([No dlfcn.h in /usr/include or /sw/include.])
   fi
   # case "$CPPFLAGS $LIBS" in
   #    *sw/*) ;;
   #    *)
   #       if test -d "$orig_NCBI/safe-sw"; then
   #           CPPFLAGS="-I$orig_NCBI/safe-sw/include $CPPFLAGS"
   #           LDFLAGS="-L$orig_NCBI/safe-sw/lib $LDFLAGS"
   #       fi
   #       ;;
   # esac
   : ${with_x=${with_xpm-no}}

   # CPPFLAGS="-F/System/Library/Frameworks/CoreServices.framework/Frameworks $CPPFLAGS"
   LIBS="-Wl,-framework,ApplicationServices $LIBS"

   OBJCXX_CXXFLAGS='-x objective-c++'
   OBJCXX_LIBS='-lobjc'
   FOUNDATION_LIBS='-framework Foundation'

   # New in macOS 10.12; don't attempt to use on older versions
   ac_cv_func_clock_gettime=no
   ac_cv_search_clock_gettime=no
   ;;
esac


#### Set makefile variables for platform-specific includes
changequote(, )dnl
COMPILER=`echo $ncbi_compiler | tr '[A-Z]' '[a-z]'`
OSTYPE=`echo $host_os | sed -e 's/[0-9.]*$//; s/-gnu[^-]*$//; y/A-Z/a-z/'`
changequote([, ])dnl


#### Check if the compiler matches one of supported compilers on this platform
if test -z "$compiler" ; then
   cat <<EOF

  Compiler $CXX $compiler_ver is not fully supported.
  Consult doc/config.html\#ref_Compilers for the list of
  fully supported platforms/compilers.
EOF
   NCBI_CAUTION([Do you still want to proceed (at your own risk)?])
   echo
   compiler="UNKNOWN"
fi


C_LIBS=$LIBS


ARCH_CPPFLAGS=
#### architecture settings, and extra C++ LIBS
if test "$with_64" = "yes" ; then
   bit64_sfx="64"
   case "$host:$compiler" in
    sparc-sun-solaris*:WorkShop5 | sparc-sun-solaris*:KCC )
      ARCH_CFLAGS="-xtarget=ultra -xarch=v9"
      ;;
    sparc-sun-solaris*:WorkShop51 )
      ARCH_CFLAGS="-xtarget=ultra -xarch=v9"
      LIBS="-Bstatic -L$CXX_PATH/../lib -lCstd -lCrun -Bdynamic $LIBS -lc"
      ;;
    *solaris*:WorkShop59 | *solaris*:WorkShop51? )
      ARCH_CFLAGS="-m64"
      LIBS="-lCstd -lCrun $LIBS -lc"
      ;;
changequote(, )dnl
    *solaris*:WorkShop5* )
      ARCH_CFLAGS="-xtarget=generic64"
      # Redundant for programs, but necessary for dlopen-able shared libs,
      # at least in the x86 ReleaseMT configuration.
      LIBS="-lCstd -lCrun $LIBS -lc"
      ;;
changequote([, ])dnl
    mips*:GCC )
      ARCH_CFLAGS="-mips64"
      ;;
    *:GCC | *Clang )
      # May not work prior to GCC 3.1.
      ARCH_CFLAGS="-m64"
      case $host_os in darwin*) ARCH_CPPFLAGS="-m64" ;; esac
      ;;

    mips-sgi-irix*:MIPSpro73 )
      ARCH_CFLAGS="-64"
      CPPFLAGS="$ARCH_CFLAGS $CPPFLAGS"
      AR=${AR:="$CXX $ARCH_CFLAGS -ar -WR,-v -o"}
      ;;
    mips-sgi-irix*:KCC )
      ARCH_CFLAGS="-64"
      ;;
    * )
      AC_MSG_ERROR([Do not know how to compile 64-bit with compiler $CXX $compiler_ver $host:$compiler])
      ;;
   esac
else
   bit64_sfx=
   ARCH_CFLAGS=
   if test "$with_64" = "no" ; then
      case "$host:$compiler" in
       *solaris*:WorkShop* | *solaris*:KCC )
         ARCH_CFLAGS="-xtarget=generic"
         ;;
       mips*:GCC )
         ARCH_CFLAGS="-mipsn32"
         ;;
       *:GCC | *Clang )
         # May not work prior to GCC 3.1.
         ARCH_CFLAGS="-m32"
         case $host_os in darwin*) ARCH_CPPFLAGS="-m32" ;; esac
         ;;

       mips-sgi-irix*:MIPSpro73 )
         ARCH_CFLAGS="-n32"
         CPPFLAGS="$ARCH_CFLAGS $CPPFLAGS"
         AR=${AR:="$CXX $ARCH_CFLAGS -ar -WR,-v -o"}
         ;;
       mips-sgi-irix*:KCC )
         ARCH_CFLAGS="-n32"
         ;;
       * )
         # Just a warning, since 32-bit mode is typically the default anyway...
         AC_MSG_WARN([Do not know how to compile 32-bit with compiler $CXX $compiler_ver $host:$compiler])
         ;;
      esac
   fi
   case "$host:$compiler" in
    *solaris*:WorkShop5 )
      LIBS="-Bstatic -L$CXX_PATH/../SC5.0/lib -lm -Bdynamic $LIBS"
      MATH_LIBS=" "
      ;;
    *solaris*:WorkShop51 )
      LIBS="-Bstatic -L$CXX_PATH/../lib -lCstd -lCrun -lm -Bdynamic $LIBS -lc"
      MATH_LIBS=" "
      ;;
    sparc-sun-solaris*:WorkShop54 )
      # Using this (still very conservative) non-generic XARCH flavor allows
      # compiler to use the extended instruction set which reportedly speeds
      # up the locking of at least some STL classes by allowing them to use
      # atomic increment instead of mutex;  also seems to fix something that
      # caused misterios basic_string<> related crashes in the
      # WorkShop54 -xarch=v8 -mt configuration).
      ARCH_CFLAGS="-xarch=v8plus"
      LIBS="-lCstd $LIBS -lCrun -lc"
      ;;
changequote(, )dnl
    *solaris*:WorkShop5* )
      # MATH_LIBS=" "
      # Redundant for programs, but necessary for dlopen-able shared libs,
      # at least in the x86 ReleaseMT configuration.
      LIBS="-lCstd $LIBS -lCrun -lc"
      ;;
changequote([, ])dnl
    *irix*:MIPSpro73 | *irix*:KCC )
      ARCH_CFLAGS="-n32"
      ;;
   esac
fi

case "$host_os:$host_cpu" in
   linux*:alpha*)
      ARCH_CFLAGS="-mieee $ARCH_CFLAGS"
      ;;
esac

CPPFLAGS="$ARCH_CPPFLAGS $CPPFLAGS"
CFLAGS="$ARCH_CFLAGS $CFLAGS"
CXXFLAGS="$ARCH_CFLAGS $CXXFLAGS"
LDFLAGS="$ARCH_CFLAGS $LDFLAGS"

: ${MATH_LIBS:="-lm"}

### Math lib to be always linked in
LIBS="$MATH_LIBS $LIBS"
C_LIBS="$MATH_LIBS $C_LIBS"

### Should go before any test compiler runs
AC_LANG_PUSH(C)
AC_GNU_SOURCE
AC_LANG_POP(C)

if test -n "$with_64"; then
   AC_CACHE_CHECK([whether this system supports --with(out)-64],
      ncbi_cv_sys_with64_ok,
      [AC_LINK_IFELSE([
          AC_LANG_PROGRAM([@%:@include <string>],
                          [std::string* sp = new std::string("foo");])],
          ncbi_cv_sys_with64_ok=yes, ncbi_cv_sys_with64_ok=no)])
   if test "$ncbi_cv_sys_with64_ok" = no; then
      AC_MSG_ERROR([cannot continue; please try different options])
   fi
fi

case "$host_os:$compiler" in
   darwin*:GCC | darwin*Clang )
      AC_CACHE_CHECK([whether $CC supports -Wl,-rpath],
         ncbi_cv_prog_cc_wl_rpath,
         [orig_LDFLAGS=$LDFLAGS
          LDFLAGS="-Wl,-rpath,. $LDFLAGS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
             [ncbi_cv_prog_cc_wl_rpath=yes], [ncbi_cv_prog_cc_wl_rpath=no])
          LDFLAGS=$orig_LDFLAGS])
      ;;
   cygwin* )
      ;;
   *:GCC | *:ICC | *Clang )
      AC_CACHE_CHECK([whether $CC has an option to export all symbols],
         ncbi_cv_prog_cc_export_all,
         [orig_LDFLAGS=$LDFLAGS
          ncbi_cv_prog_cc_export_all=no
          for x in -Wl,--export-all-symbols -Wl,-export-dynamic -rdynamic \
                   -Wl,-E; do
             LDFLAGS="$x $orig_LDFLAGS"
             AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
                [ncbi_cv_prog_cc_export_all=$x])
             test "x$ncbi_cv_prog_cc_export_all" = "xno"  ||  break
          done
          LDFLAGS=$orig_LDFLAGS])
      test "$ncbi_cv_prog_cc_export_all" = no  || \
         LDFLAGS="$ncbi_cv_prog_cc_export_all $LDFLAGS"
      AC_CACHE_CHECK([whether $CC supports -Wl,--{en,dis}able-new-dtags],
         ncbi_cv_prog_cc_new_dtags,
         [orig_LDFLAGS=$LDFLAGS
          LDFLAGS="-Wl,--enable-new-dtags $LDFLAGS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
             [ncbi_cv_prog_cc_new_dtags=yes], [ncbi_cv_prog_cc_new_dtags=no])
          LDFLAGS=$orig_LDFLAGS])
      if test "$ncbi_cv_prog_cc_new_dtags" = yes; then
          if test "$with_hard_runpath" = yes; then
             LDFLAGS="-Wl,--disable-new-dtags $LDFLAGS"
          else
             LDFLAGS="-Wl,--enable-new-dtags $LDFLAGS"
          fi
      fi
      ;;
esac

AC_CACHE_CHECK([whether $CC has an option to discard unneeded shared libraries],
   ncbi_cv_prog_cc_as_needed,
   [orig_LDFLAGS=$LDFLAGS
    ncbi_cv_prog_cc_as_needed=no
    for x in -Wl,--as-needed; do
       LDFLAGS="$orig_LDFLAGS $x"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
          [ncbi_cv_prog_cc_as_needed=$x])
       test "x$ncbi_cv_prog_cc_as_needed" = "xno"  ||  break
    done
    LDFLAGS=$orig_LDFLAGS])
case "$ncbi_cv_prog_cc_as_needed" in
   -Wl,--as-needed )
      AS_NEEDED=-Wl,--as-needed
      NO_AS_NEEDED=-Wl,--no-as-needed
      ;;
   no )
      AS_NEEDED=
      NO_AS_NEEDED=
      ;;
esac
       
AC_CACHE_CHECK([whether $CC has an option to link in whole static archives],
   ncbi_cv_prog_cc_whole_archive,
   [orig_LDFLAGS=$LDFLAGS
    ncbi_cv_prog_cc_whole_archive=no
    for x in -Wl,--whole-archive; do
       LDFLAGS="$orig_LDFLAGS $x `echo $x | sed -e 's/--/--no-/'`"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
          [ncbi_cv_prog_cc_whole_archive=$x])
       test "x$ncbi_cv_prog_cc_whole_archive" = "xno"  ||  break
    done
    LDFLAGS=$orig_LDFLAGS])
case "$ncbi_cv_prog_cc_whole_archive" in
   -Wl,--whole-archive )
      WHOLE_ARCHIVE=-Wl,--whole-archive
      NO_WHOLE_ARCHIVE=-Wl,--no-whole-archive
      ;;
   no )
      WHOLE_ARCHIVE=
      NO_WHOLE_ARCHIVE=
      ;;
esac

case "$compiler" in
 *Clang)
   CFLAGS="$CFLAGS -Wno-deprecated-register"
   CXXFLAGS="$CXXFLAGS -Wno-deprecated-register"

   case "$host_os:$CXX" in
      darwin[[0-9]].*:/usr/bin/* | darwin1[[0-2]].*:/usr/bin/* )
         ncbi_cv_prog_cxx_stdlib_libcxx=no
         ;;
   esac

   AC_CACHE_CHECK([whether $CXX supports -stdlib=libc++],
      ncbi_cv_prog_cxx_stdlib_libcxx,
      [orig_CXX=$CXX
       CXX="$orig_CXX -stdlib=libc++"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <stdexcept>],
             [std::logic_error le("Inconceivable!");])],
          [ncbi_cv_prog_cxx_stdlib_libcxx=yes],
          [ncbi_cv_prog_cxx_stdlib_libcxx=no])
       CXX=$orig_CXX])
   test "$ncbi_cv_prog_cxx_stdlib_libcxx" = no  ||  CXX="$CXX -stdlib=libc++"
   ;;
 *)   
   ncbi_cv_prog_cxx_stdlib_libcxx=no
   ;;
esac

AC_CHECK_DECL([_LIBCPP_VERSION], [], [], [@%:@include <iosfwd>])

modern_cxx_stds="-std=gnu++17 -std=gnu++1z"
modern_c_stds="-std=gnu18 -std=gnu17 -std=gnu11 -std=gnu1x -std=gnu99"
modern_c_stds="$modern_c_stds -std=gnu9x"

if test "$want_cxx20" = yes; then
   modern_cxx_stds="-std=gnu++20"
fi

if test "$want_c2x" = yes; then
   modern_c_stds="-std=gnu2x $modern_c_stds"
fi

if dpkg-vendor --is Ubuntu >/dev/null 2>&1; then
   is_ubuntu=yes
else
   is_ubuntu=no
fi

AC_CACHE_CHECK([how to enable modern C++ features in $CXX],
   ncbi_cv_prog_modern_cxx,
   [orig_CXX=$CXX
    ncbi_cv_prog_modern_cxx=no
    for x in $modern_cxx_stds ''; do
       CXX="$orig_CXX $x"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <numeric>],
          [return 3 - std::gcd(123, 456);])],
          [ncbi_cv_prog_modern_cxx=$x])
          test "x$ncbi_cv_prog_modern_cxx" = "xno"  ||  break
       done
       CXX=$orig_CXX])
if test "$ncbi_cv_prog_modern_cxx" = no; then
   if test "$want_cxx20" = yes; then
      AC_MSG_ERROR([Please upgrade to a compiler supporting C++20, such as GCC 10 or newer.])
   else
      AC_MSG_ERROR([Please upgrade to a compiler supporting C++ '17, such as GCC 7.1 or newer.])
   fi
else
   CXX="$CXX $ncbi_cv_prog_modern_cxx"
fi

case "$CXX:::$ac_cv_prog_CXXCPP" in
   *++17*:::*++14* ) AS_UNSET(ac_cv_prog_CXXCPP) ;;
esac


AC_LANG_PUSH(C)
AC_CACHE_CHECK([how to enable modern C features in $CC],
   ncbi_cv_prog_modern_c,
   [orig_CC=$CC
    ncbi_cv_prog_modern_c=no
    for x in -xc99=all $modern_c_stds; do
       case "$x" in
          -std=gnu* ) x="$x -fgnu89-inline" ;;
       esac
       CC="$orig_CC $x"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
          [ncbi_cv_prog_modern_c=$x])
          test "x$ncbi_cv_prog_modern_c" = "xno"  ||  break
       done
       CC=$orig_CC])

if test "$host_cpu" != x86_64; then
   : ${with_sse42=no}
fi

if test "${with_sse42-$with_optimization}" = yes; then
   orig_CC=$CC
   AC_CACHE_CHECK([whether $CC supports -msse4.2],
      ncbi_cv_prog_c_sse42,
      [orig_CC=$CC
       CC="$CC -msse4.2"
       AC_LINK_IFELSE(
          [AC_LANG_PROGRAM(
              [@%:@include <smmintrin.h>],
              [__m128i v;  _mm_cmpgt_epi64(v, v);])],
          [ncbi_cv_prog_c_sse42=yes],
          [ncbi_cv_prog_c_sse42=no])])
   if test $ncbi_cv_prog_c_sse42 = yes; then
      CC="$orig_CC -msse4.2"
      orig_CC=$CC
   elif test "$with_sse42" = yes; then
      AC_MSG_ERROR([SSE 4.2 support explicitly requested but unavailable.])
   else
      CC=$orig_CC
   fi
fi
AC_LANG_POP(C)
test "$ncbi_cv_prog_modern_c" = no  ||  CC="$CC $ncbi_cv_prog_modern_c"

if test "${with_sse42-$with_optimization}" = yes; then
   orig_CXX=$CXX
   AC_CACHE_CHECK([whether $CXX supports -msse4.2],
      ncbi_cv_prog_cxx_sse42,
      [CXX="$CXX -msse4.2"
       AC_LINK_IFELSE(
          [AC_LANG_PROGRAM(
              [@%:@include <smmintrin.h>],
              [__m128i v;  _mm_cmpgt_epi64(v, v);])],
          [ncbi_cv_prog_cxx_sse42=yes],
          [ncbi_cv_prog_cxx_sse42=no])])
   if test $ncbi_cv_prog_cxx_sse42 = yes; then
      CXX="$orig_CXX -msse4.2"
      orig_CXX=$CXX
   elif test "$with_sse42" = yes; then
      AC_MSG_ERROR([SSE 4.2 support explicitly requested but unavailable.])
   else
      CXX=$orig_CXX
   fi
fi

case "$host_os:$compiler" in
 solaris*:GCC )
   # On Solaris, GCC defaults to setting _XOPEN_SOURCE (to 500) only
   # in C++ mode.  Set it for C code as well to ensure consistent
   # header behavior, taking care to match the C standard version
   # (as enforced by <sys/feature_tests.h>).
   case "$ncbi_cv_prog_modern_c" in
      no) CC="$CC -D_XOPEN_SOURCE=500" ;;
      *)  CC="$CC -D_XOPEN_SOURCE=600" ;;
   esac
   ;;
esac


### large file support (switch to AC_SYS_LARGEFILE?)
case "$host_os:$compiler:$compiler_version" in
    cygwin* ) with_lfs=no ;;
    *:GCC:* | *:ICC:* | *Clang:* ) : ${with_lfs=yes} ;;
esac

if test "$with_lfs" = "yes" ; then
   LFSFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
   # Modern BSD-based systems (including Mac OS X) already use a 64-bit
   # off_t, but don't necessarily provide explicit ...64 variants of all
   # relevant functions.
   case "$host_os" in
      *bsd* | darwin* ) ;;
      * ) LFSFLAGS="$LFSFLAGS -D_LARGEFILE64_SOURCE" ;;
   esac
   CPPFLAGS="$LFSFLAGS $CPPFLAGS"
fi

tabchar='	'
wschars=" $tabchar"
wsrx="[[$wschars]]"

#### Flags to enable (potentially unsafe) extra optimization.
if test "$skip_fast_flags" = no -a -z "$DEF_FAST_FLAGS" ; then
   case "$compiler:$compiler_version" in
      GCC:* | *Clang:* )
        DEF_FAST_FLAGS="-O3 -finline-functions -fstrict-aliasing"
        # DEF_FAST_FLAGS="$DEF_FAST_FLAGS -ffast-math" ;;
        case "$with_profiling:$compiler:$compiler_version:$host_cpu" in
           yes:* | *:AppleClang:15*:arm* )
              ;;
           * )
              # incompatible with -pg; breaks exception handling with
              # Apple Clang 15 on Silicon.
              DEF_FAST_FLAGS="$DEF_FAST_FLAGS -fomit-frame-pointer"
              ;;
        esac
        ;;
      WorkShop5[[89]]* | WorkShop510 )
        # Limit optimization to -xO2 (-O now maps to -xO3) due to compiler bugs.
        subst="s/[$wsrx]-x*O[[1-9]]*//g"
        CFLAGS="`  echo \" $CFLAGS\"   | sed -e \"$subst\"` -xO2"
        CXXFLAGS="`echo \" $CXXFLAGS\" | sed -e \"$subst\"` -xO2"
        LDFLAGS="` echo \" $LDFLAGS\"  | sed -e \"$subst\"` -xO2"
        DEF_FAST_FLAGS="-xO2"
        ;;
      WorkShop* )
        DEF_FAST_FLAGS="-fast"
        case "$with_ncbi_public:$host_cpu" in
           yes:sparc* )
              DEF_FAST_FLAGS="$DEF_FAST_FLAGS -xtarget=ultra"
              ;;
           *:i?86)
              case "$compiler_ver" in
                *5.[[0-4]]*)
                  # Work around a WorkShop standard library bug.
                  DEF_FAST_FLAGS="$DEF_FAST_FLAGS -D_RWSTD_NO_TEST_AND_SET"
                  ;;
              esac
              ;;
        esac
        # (Re)include ARCH_CFLAGS here because -fast implies -xtarget=native.
        DEF_FAST_FLAGS="$DEF_FAST_FLAGS $ARCH_CFLAGS"
        ;;
      KCC:* )
        DEF_FAST_FLAGS="+K3"
        case "$host_os" in
           solaris* )  DEF_FAST_FLAGS="$DEF_FAST_FLAGS -fast $ARCH_CFLAGS" ;;
        esac
        ;;
      ICC:??? | ICC:1??? )
        # Core 2; ICC 11 goes up to SSE4.2 (i7), ICC 12 up to CORE-AVX-I
        DEF_FAST_FLAGS="-O3 -axSSSE3 -ip"
        ;;
      ICC:* )
        DEF_FAST_FLAGS="-O3 -ffp-model=fast -march=corei7" # -ipo
        ;;
      MIPSpro* )
        # -Ofast would be preferable, but runs into resource limits when
        # building libxblast.so. :-/
        DEF_FAST_FLAGS="-O2"
        ;;
      Compaq:* )
        DEF_FAST_FLAGS="-fast"
        ;;
      * )
        DEF_FAST_FLAGS="-O"
        ;;
   esac
fi

: ${FAST_CFLAGS="$DEF_FAST_FLAGS"}
: ${FAST_CXXFLAGS="$DEF_FAST_FLAGS"}
: ${FAST_LDFLAGS="$DEF_FAST_FLAGS"}


#### DLLs

# Generate position-independent code (PIC)
if test -z "$CFLAGS_DLL"  -a  -z "$CXXFLAGS_DLL" ; then
   case "$host_os:$compiler" in
    darwin*:GCC | darwin*Clang )
      CFLAGS_DLL="-fno-common"
      CXXFLAGS_DLL="-fno-common"
      ;;
    *:GCC | *Clang | linux* )
      CFLAGS_DLL="-fPIC"
      CXXFLAGS_DLL="-fPIC"
      ;;
    solaris*:WorkShop* | irix*:MIPSpro73 | \
    solaris*:KCC | irix*:KCC )
      CFLAGS_DLL="-KPIC"
      CXXFLAGS_DLL="-KPIC"
      ;;
   esac
fi

# Flag for setting the runtime library search path
if test -z "$CONF_f_runpath" ; then
   case "$host_os:$compiler" in
    solaris* )
      CONF_f_runpath="-R"
      ;;
    linux*:[[GI]]CC | linux*Clang | *bsd*:GCC | *bsd*Clang | cygwin*:GCC \
    | osf*:GCC )
      CONF_f_runpath="-Wl,-rpath,"
      ;;
    irix*:* | linux*:KCC | *:Compaq )
      CONF_f_runpath="-rpath "
      ;;
    darwin* )
      test "$ncbi_cv_prog_cc_wl_rpath" = no  ||  CONF_f_runpath="-Wl,-rpath,"
      ;;
   esac
fi
case "$host_os:$ncbi_cv_prog_cc_wl_rpath" in
    linux*|solaris* )
        origin="'\$\$ORIGIN'"
        RUNPATH_ORIGIN="$CONF_f_runpath$origin"
        ;;
    darwin*:yes )
        origin='@executable_path'
        RUNPATH_ORIGIN="$CONF_f_runpath$origin"
        ;;
    * )
        origin=
        RUNPATH_ORIGIN="-DNCBI_RPO_SUFFIX_EATER="
        ;;
esac

AC_PATH_PROG(DPKG_ARCHITECTURE, dpkg-architecture)
if test -x "$DPKG_ARCHITECTURE" \
    &&  $DPKG_ARCHITECTURE -qDEB_HOST_MULTIARCH >/dev/null 2>&1; then
   multiarch=`$DPKG_ARCHITECTURE -qDEB_HOST_MULTIARCH`
else
   multiarch=`echo $host | sed -e 's/-unknown-/-/; [s/^i[3-9]86-/^i\[3-9\]86/]'`
fi

case "$compiler:$compiler_version:$with_bin_release:$ncbi_cv_prog_cxx_stdlib_libcxx" in
  GCC:*:yes:no | *Clang:*:yes:no )
    libstdcxx=`$CXX $LDFLAGS -print-file-name=libstdc++.a`
    case "$host_os:$libstdcxx" in
       cygwin*:/*)
          LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition"
          LDFLAGS="$LDFLAGS -static-libstdc++ -static-libgcc"
          ;;
       *:/*)
          # LIBS="$libstdcxx $LIBS"
          # LINK=$C_LINK
          LDFLAGS="$LDFLAGS -static-libstdc++"
          ;;
       *)
          AC_MSG_ERROR([Unable to find static libstdc++ requested by --with-bin-release.])
          ;;
    esac
    ;;
  GCC:* | *Clang:*:*:* )
    # Need to specify runpath for compiler-provided libraries
    major=6 # true for all supported versions at present
    found=false
    for f in libstdc++.so.$major libgcc_s.so.1 libstdc++.a; do
        path=`$CXX $LDFLAGS -print-file-name=$f`
        dir=`dirname "$path"`
        abs_dir=`cd "$dir" && pwd`
        case "$dir:$abs_dir" in
            *:/lib | *:/lib64 | *:/usr/lib | *:/usr/lib32 | *:/usr/lib64 \
            | *:/usr/lib/$multiarch )
               # no rpath needed
               break
               ;;
            /* )
               found=true
               break
               ;;
        esac
    done
    if test "$found" = "true" -a -n "$CONF_f_runpath"; then
        LDFLAGS="$CONF_f_runpath$dir $LDFLAGS"
        case "$host_os" in
           osf*)
              # the linker doesn't merge -rpath flags...
              CONF_f_runpath="$CONF_f_runpath$dir:"
              ;;
           solaris*)
              # avoid interference from possible older versions in /usr/sfw.
              LDFLAGS="-L$dir $LDFLAGS"
              ;;
        esac
    fi
    ;;
  ICC:6?? )
    # Seems to use libcxa.so.1 even without -i_dynamic...
    LDFLAGS="$CONF_f_runpath$compiler_root/lib $LDFLAGS"
    ;;
  ICC:7?? )
    # Favor the static version, as libcxa.so.3 isn't exactly common....
    # (Undocumented, and unavailable at all in older versions. :-/)
    LDFLAGS="-static-libcxa $LDFLAGS"
    ;;
  ICC:8?? )
    # In principle, these settings should work, and avoid the need to
    # depend on Intel's libraries at runtime.
    #  APP_LDFLAGS="-static-libcxa $APP_LDFLAGS"
    #  DLL_LDFLAGS="-nodefaultlibs $DLL_LDFLAGS"
    # In practice, they can break applications that use plugins. :-/
    LDFLAGS="$CONF_f_runpath$compiler_root/lib $LDFLAGS"
    ;;
  ICC:9?? )
    # -i-static moved from common LDFLAGS to accommodate those few
    # DLLs (plugins for external programs such as Python) that need to
    # link ICC's libraries dynamically.
    APP_LDFLAGS="-i-static $APP_LDFLAGS"
    DLL_LDFLAGS="-i-static -nodefaultlibs $DLL_LDFLAGS"
    # Running icpc on a bunch of object files doesn't always ensure that
    # the C++ standard library is actually linked in, and we shouldn't
    # rely on help from wrapper scripts.
    LINK="$LINK -Kc++"
    ;;
  ICC:1???:* )
    case "$host_cpu" in
       i?86   ) intel_cpu_name=ia32      ;;
       x86_64 ) intel_cpu_name=intel64   ;;
       *      ) intel_cpu_name=$host_cpu ;;
    esac
    LDFLAGS="$CONF_f_runpath$compiler_root/lib/$intel_cpu_name $LDFLAGS"
    # Suppress "warning #10237: -lcilkrts linked in dynamically, static
    # library not available" which is not a problem in practice due to
    # as-needed linkage.
    APP_LDFLAGS="-static-intel -diag-disable 10237 $APP_LDFLAGS"
    DLL_LDFLAGS="-static-intel -diag-disable 10237 -nodefaultlibs $DLL_LDFLAGS"
    # Redundant for apps, but necessary for plugins to be adequately
    # self-contained, at least on 32-bit Linux.
    if test "$with_bin_release" = "yes"; then
       LDFLAGS="$LDFLAGS -static-libstdc++"
    elif test "$with_dll" != "no"; then
       LIBS="$LIBS -lstdc++ -lgcc_s"
    fi
    LINK="$LINK -Kc++"
    # Defining _GCC_NEXT_LIMITS_H ensures that <limits.h> chaining doesn't
    # stop short, as can otherwise happen. :-/
    CPPFLAGS="$CPPFLAGS -D_GCC_NEXT_LIMITS_H"
    ;;
   ICC:* )
    CPPFLAGS="$CPPFLAGS -D_GCC_NEXT_LIMITS_H"
    CFLAGS="$CFLAGS -ffp-model=precise"
    CXXFLAGS="$CXXFLAGS -ffp-model=precise"
    ;;
esac

# DLLs and profiling don't mix on all platforms
if test "$with_profiling" = "yes" ; then
   case "$host_os" in
      linux*) # any others?
         case "$with_dll" in
            yes) AC_MSG_ERROR([This platform does not support DLL profiling.])
                 ;;
            no) ;;
            *) with_dll=no ;;
         esac
      ;;
   esac
fi

# Whether to build DLLs or static (and whether by default, or forcibly)
LIB_OR_DLL="lib"
if test "$with_dll" = "yes" ; then
   case "$host_os:$compiler" in
    linux*:GCC | linux*Clang | irix* | solaris*:WorkShop* | linux*:ICC \
    | solaris*:GCC | osf* | darwin*:GCC | darwin*Clang | freebsd*:GCC \
    | freebsd*Clang | *:KCC )
      ;;
    * )
      echo
      echo "DLLs may not be buildable by $CXX $compiler_ver on $host!"
      NCBI_CAUTION([Do you still want to try build DLLs (at your own risk)?])
      echo
      ;;
   esac
fi

case "$with_dll:$with_static" in
   yes:yes) LIB_OR_DLL="both"; dll_sfx="DLL+static" ;;
   yes:*)   LIB_OR_DLL="dll";  dll_sfx="DLL" ;;
   *:no)    AC_MSG_ERROR([--without-static requires --with-dll]) ;;
   *)       LIB_OR_DLL="lib";  dll_sfx=""  ;;
esac

DLL=
DLL_LIB_SETTING='$(DLL_DLIB)'
IF_WITH_DLL=
UNLESS_WITH_DLL='# '
STATIC="-static"
USUAL_AND_DLL=both
USUAL_AND_LIB=both

case "$LIB_OR_DLL" in
   dll)
       STATIC=
       USUAL_AND_DLL=dll
       ;;
   lib)
       DLL=-dll
       DLL_LIB_SETTING='$(DLL_LIB)'
       IF_WITH_DLL='# '
       UNLESS_WITH_DLL=
       USUAL_AND_LIB=lib
       ;;
esac

AC_SUBST(DLL)
AC_SUBST(DLL_LIB_SETTING)
AC_SUBST(IF_WITH_DLL)
AC_SUBST(UNLESS_WITH_DLL)
AC_SUBST(STATIC)
AC_SUBST(USUAL_AND_DLL)
AC_SUBST(USUAL_AND_LIB)


#### GNU compiler::  common flags and definitions
if test "$compiler" = "GCC" ; then
   CFLAGS="-Wall -Wno-format-y2k $CFLAGS"
   CXXFLAGS="-Wall -Wno-format-y2k $CXXFLAGS"
   case "$host_os" in
      solaris* )  CPPFLAGS="-D__EXTENSIONS__ $CPPFLAGS" ;;
      irix*    )  CXXFLAGS="$CXXFLAGS -D_LANGUAGE_C_PLUS_PLUS" ;;
   esac
   # orig_CFLAGS=$CFLAGS
   # orig_CXXFLAGS=$CXXFLAGS
   # flag=-fno-merge-debug-strs
   # CFLAGS="$flag $CFLAGS"
   # CXXFLAGS="$flag $CXXFLAGS"
   # AC_CACHE_CHECK([whether GCC supports $flag], ncbi_cv_prog_gcc_nomerge,
   #    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[return 0;]])],
   #                       ncbi_cv_prog_gcc_nomerge=yes,
   #                       ncbi_cv_prog_gcc_nomerge=no)])
   # if test "$ncbi_cv_prog_gcc_nomerge" = no; then
   #    CFLAGS=$orig_CFLAGS
   #    CXXFLAGS=$orig_CXXFLAGS
   # fi
fi


#### Clang compiler::  common flags and definitions
case "$compiler" in
   *Clang ) 
      CFLAGS="-Wall -Wno-format-y2k $CFLAGS"
      CXXFLAGS="-Wall -Wno-format-y2k $CXXFLAGS"
      case "$host_os:$compiler_version" in
         linux*:1[[4-9]]?? | linux*:[[2-9]]??? )
            # Normally an error, breaking some Boost.Test 1.76 usage;
            # no obvious middle ground.
            CXXFLAGS="-Wno-enum-constexpr-conversion $CXXFLAGS"
            APP_LDFLAGS="-nopie $APP_LDFLAGS"            
            ;;
      esac
      ;;
esac


#### KAI compiler::  common flags and definitions
if test "$compiler" = "KCC" ; then
   AR=${AR:="$CXX $MT_FLAG -o"}
   CFLAGS="--display_error_number --c $CFLAGS"
   CXXFLAGS="--display_error_number --one_instantiation_per_object $CXXFLAGS"
   case "$host_os" in
      solaris* )  CPPFLAGS="-D__EXTENSIONS__ -D__STDC__=0 $CPPFLAGS" ;;
   esac
fi


#### Intel compiler::  common flags and definitions
if test "$compiler" = "ICC" ; then
   if test -n "$icc_license" ; then
      icc_CC="$CC"
      icc_CXX="$CXX"
      CC="./compilers/unix/cxx_filter.ICC.sh $CC"
      CXX="./compilers/unix/cxx_filter.ICC.sh $CXX"
   fi
fi


#### How to ensure that the compiler will account for potential aliasing
case "$compiler" in
   GCC | *Clang ) NO_STRICT_ALIASING=-fno-strict-aliasing ;;
   ICC ) NO_STRICT_ALIASING='-falias -ffnalias' ;;
   WorkShop* ) NO_STRICT_ALIASING='-xalias_level=any' ;;
   * ) NO_STRICT_ALIASING=
esac

dnl Autoconf 2.62+ has an AC_PATH_PROGS_FEATURE_CHECK macro that could
dnl also be useful.
AX_CHECK_GNU_MAKE
AC_PATH_PROG(AWK, ${ac_cv_prog_AWK-awk})
AC_PATH_PROG(MAKE, ${ax_cv_gnu_make_command-make})
export MAKE

#### Automatic generation of dependencies for/by the "make" utility
case "$host_os" in
   solaris* )  KeepStateTarget=".KEEP_STATE:" ;;
esac

if test "$with_autodep" = "yes" ; then
   Rules="rules_with_autodep"
elif test "$with_autodep" = "no" ; then
   Rules="rules"
elif $MAKE --version 2>/dev/null | grep 'GNU Make' >/dev/null ; then
   Rules="rules_with_autodep"
else
   Rules="rules"
fi


### Support for precompiled headers
GCCPCH="#"
if test "$with_pch" = "yes"; then
   case "$compiler" in
      GCC | *Clang ) ;;
      * ) ncbi_cv_cxx_pch=no ;;
   esac
   AC_CACHE_CHECK([whether $CXX supports precompiled headers], ncbi_cv_cxx_pch,
      [echo '@%:@include <iostream>' > conftest.hpp
       echo $CXX $CPPFLAGS $CXXFLAGS -xc++-header -c conftest.hpp >&AS_MESSAGE_LOG_FD
       if $CXX $CPPFLAGS $CXXFLAGS -xc++-header -c conftest.hpp >&AS_MESSAGE_LOG_FD 2>&1 \
         &&  test -f conftest.hpp.gch; then
          ncbi_cv_cxx_pch=yes
       else
          ncbi_cv_cxx_pch=no
       fi])
   if test "$ncbi_cv_cxx_pch" = "yes"; then
      if test "$Rules" = "rules"; then
         AC_MSG_WARN([Your version of make does not fully support PCH-related dependencies.])
      fi
      CXXFLAGS="-DNCBI_USE_PCH $CXXFLAGS"
      GCCPCH=""
   fi
fi


#### Tools
AC_PROG_LN_S
case "$LN_S" in
    /*) ;;
    * ) LN_S=/bin/$LN_S ;;
esac

AC_PROG_RANLIB
AC_CHECK_PROG(AR, ar, ar cr, ErrorCannotFind_AR)
if test "x$RANLIB" != "x:"; then
   AC_CACHE_CHECK([ranlib's effectiveness], ncbi_cv_prog_ranlib_effect,
      [AC_LANG_CONFTEST([AC_LANG_SOURCE([[int libfunc(void) { return 0; }]])])
       echo $CXX $CPPFLAGS $CXXFLAGS -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD
       $CXX $CPPFLAGS $CXXFLAGS -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD 2>&1
       echo $AR conftest.a conftest.o >&AS_MESSAGE_LOG_FD
       $AR conftest.a conftest.o >&AS_MESSAGE_LOG_FD 2>&1
       save_LIBS=$LIBS
       LIBS="conftest.a $LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern int libfunc(void);]],
                                       [[return libfunc();]])],
                      [ok_without=true], [ok_without=false])
       echo $RANLIB conftest.a >&AS_MESSAGE_LOG_FD
       $RANLIB conftest.a >&AS_MESSAGE_LOG_FD
       AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern int libfunc(void);]],
                                       [[return libfunc();]])],
                      [ok_with=true], [ok_with=false])
       LIBS=$save_LIBS
       case $ok_with:$ok_without in
          true:false)  ncbi_cv_prog_ranlib_effect=positive ;;
          false:true)  ncbi_cv_prog_ranlib_effect=negative ;;
          true:true)   ncbi_cv_prog_ranlib_effect=neutral  ;;
          false:false) ncbi_cv_prog_ranlib_effect=unknown  ;;
       esac
      ])
   case "$ncbi_cv_prog_ranlib_effect" in
      negative) RANLIB=: ;;
      unknown)
        AC_MSG_WARN([Failed to make a working library with or without ranlib.])
        ;;
   esac
fi
if test "$with_strip" = yes; then
   AC_CHECK_PROG(STRIP, strip, strip, @:)
   AC_CACHE_CHECK([whether strip loses runtime type information],
      ncbi_cv_strip_loses_rtti,
      [if test "$cross_compiling" = yes; then
          case "$host_os" in
             darwin* ) ncbi_cv_strip_loses_rtti=yes ;;
             # No problems observed elsewhere so far.
             *       ) ncbi_cv_strip_loses_rtti=no  ;;
          esac
       else
          AC_LANG_CONFTEST([AC_LANG_PROGRAM(
                               [[@%:@include <iostream>
                                 @%:@include <typeinfo>
                                 struct SomeStruct { };]],
                               [[std::cout << typeid(SomeStruct).name();]])])
          echo $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -o conftest$ac_exeext \
             conftest.$ac_ext >&AS_MESSAGE_LOG_FD
          $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -o conftest$ac_exeext \
             conftest.$ac_ext >&AS_MESSAGE_LOG_FD 2>&1
          $STRIP conftest$ac_exeext
          if (ulimit -c 0; ./conftest$ac_exeext) >/dev/null 2>&1; then
             ncbi_cv_strip_loses_rtti=no
          else
             ncbi_cv_strip_loses_rtti=yes
          fi
          rm -rf conftest*
       fi])
   if test "$ncbi_cv_strip_loses_rtti" = "yes"; then
      NCBI_CAUTION([Do you still want to proceed (at your own risk)?])
   fi
else
   STRIP=@:
fi


# When using ccache and distcc together, ccache needs to be primary,
# so look for distcc(.sh) first.

if test -x $orig_NCBI/bin/distcc.sh ; then
   : ${DISTCC=$orig_NCBI/bin/distcc.sh}
   : ${with_distcc=yes}
fi

if test "$with_distcc" = "yes" ; then
   AC_PATH_PROG(DISTCC, distcc, distcc, [])
   if test -n "$DISTCC" ; then
      # Test distcc reasonably thoroughly to avoid possible gotchas.
      cat > distcctest.c << EOF
@%:@include <stddef.h>
@%:@if !defined(__GNUC__)  &&  !defined(offsetof)
@%:@  define offsetof(T, F) ((size_t)((char*) &(((T*) 0)->F) - (char*) 0))
@%:@endif
struct S { int x; };
int f() { return offsetof(struct S, x); }
EOF
      DISTCC_FALLBACK=0
      export DISTCC_FALLBACK
      AC_CACHE_CHECK([whether any distcc servers are available],
         ncbi_cv_prog_distcc_servers,
         [$DISTCC $CC -c distcctest.c 2>&AS_MESSAGE_LOG_FD
          case $? in
            # 102: bind failed
            # 103: connect failed
            # 106: bad hostspec
            # 107: I/O error
            # 109: protocol error
            # 113: access denied
            # 116: no hosts defined
            102 | 103 | 106 | 107 | 109 | 113 | 116 )
             ncbi_cv_prog_distcc_servers=no ;;
            * )
             ncbi_cv_prog_distcc_servers=yes ;;
          esac])
      if test "$ncbi_cv_prog_distcc_servers" = no; then
         AS_UNSET(DISTCC)
      fi
      if test -n "$DISTCC" ; then
         AC_CACHE_CHECK([whether $DISTCC is compatible with $CC],
            ncbi_cv_prog_distcc_vs_cc,
            [if $DISTCC $CC -c distcctest.c 2>&AS_MESSAGE_LOG_FD ; then
                ncbi_cv_prog_distcc_vs_cc=yes
             else
                ncbi_cv_prog_distcc_vs_cc=no
             fi])
         if test "$ncbi_cv_prog_distcc_vs_cc" = yes; then
            CC_WRAPPER="$DISTCC $CC_WRAPPER"
         else
            AS_UNSET(DISTCC)
         fi
      fi
      if test -n "$DISTCC" ; then
         AC_CACHE_CHECK([whether $DISTCC is compatible with $CXX],
            ncbi_cv_prog_distcc_vs_cxx,
            [mv distcctest.c distcctest.cpp
             if $DISTCC $CXX -c distcctest.cpp 2>&AS_MESSAGE_LOG_FD ; then
                ncbi_cv_prog_distcc_vs_cxx=yes
             else
                ncbi_cv_prog_distcc_vs_cxx=no
             fi])
         if test "$ncbi_cv_prog_distcc_vs_cxx" = yes; then
            CXX_WRAPPER="$DISTCC $CXX_WRAPPER"
         else
            AS_UNSET(DISTCC)
         fi
      fi
      rm -f distcctest.*
   elif test "$with_distcc" = "yes" ; then
      AC_MSG_WARN([distcc explicitly requested, but not found in PATH.])
   fi
   AS_UNSET(DISTCC_FALLBACK)
fi

if test -z "$with_ccache"  -a  -n "$DISTCC"  -a  -z "$CCACHE_DIR" ; then
   # Using CCACHE together with DISTCC causes problems when the involved DISTCC
   # servers share the same home dir, as in that case the caches from
   # different servers can mix up rather badly, corrupting each other.
   # On the other hand, most NCBI accounts have $CCACHE_DIR automatically set
   # to a non-shared, per-machine location (such as "/tmp/.ccache-username").
   with_ccache="no"
fi

if test "$with_ccache" != "no"; then
   AC_PATH_PROG(CCACHE, ccache)
   if test -n "$CCACHE" ; then
      if test -n "$CC_WRAPPER"; then
         CC_WRAPPER="CCACHE_PREFIX=$CC_WRAPPER $CCACHE"
      else
         CC_WRAPPER=$CCACHE
      fi
      if test -n "$CXX_WRAPPER"; then
         CXX_WRAPPER="CCACHE_PREFIX=$CXX_WRAPPER $CCACHE"
      else
         CXX_WRAPPER=$CCACHE
      fi
   elif test "$with_ccache" = "yes"; then
      AC_MSG_WARN([ccache explicitly requested, but not found in PATH.])
   fi
fi

# Note the path, since syntax is version-specific....
AC_PATH_PROG(TAIL, tail)
AC_MSG_CHECKING([whether $TAIL accepts modern syntax (-n N)])
if $TAIL -n 1 config.log >/dev/null 2>&1; then
   TAIL_N="$TAIL -n "
   AC_MSG_RESULT(yes)
else
   TAIL_N="$TAIL -"
   AC_MSG_RESULT(no)
fi

AC_PATH_PROG(BASENAME, basename)
AC_PATH_PROG(SED, sed)
AC_PATH_PROG(TOUCH, touch, [], /bin:/usr/bin:$PATH)
dnl AC_PATH_PROG(GREP, grep)
AC_PROG_EGREP
AC_MSG_CHECKING([how to run $EGREP quietly])
if test -z "`echo foo | $EGREP -q fo+ 2>>config.log || echo $?`"; then
   EGREP_Q="$EGREP -q"
elif test -z "`echo foo | $EGREP -s fo+ 2>>config.log || echo $?`"; then
   EGREP_Q="$EGREP -s"
else
   EGREP_Q=">/dev/null $EGREP"
fi
AC_MSG_RESULT($EGREP_Q)

AC_CHECK_PROG(VALGRIND_PATH, valgrind, valgrind)

AC_PATH_PROG(LDD, ldd, [], /bin:/usr/bin:$PATH)
if test -n "$LDD"; then
   AC_MSG_CHECKING([whether $LDD accepts -r])
   if $LDD -r /bin/ls >/dev/null 2>&1; then
      AC_MSG_RESULT(yes)
      LDD_R="$LDD -r"
   else
      AC_MSG_RESULT(no)
   fi
fi

AC_PATH_PROG(UUIDGEN, uuidgen)
AC_PATH_PROG(CD_REPORTER, cd_reporter, [],
   [/am/ncbiapdata/bin:/Volumes/ncbiapdata/bin:$PATH])

#### Check if "${build_root}" is defined;  provide a default one
if test -n "${with_build_root}" ; then
   build_root=${with_build_root}
fi

signature_compiler=$compiler
case "$compiler" in
   GCC )
      if $CXX -v 2>&1 | $EGREP_Q 'LLVM'; then
         signature_compiler=LLVMGCC
      fi
      ;;
   *Clang )
      signature_compiler=Clang
      ;;
esac

### Possibly add the version to the build directory name, but preseve
### the original default when reconfiguring.
if test -z "${with_version}" -a -n "${ncbi_cv_sys_xdir_ln}"; then
   with_version=${ncbi_cv_with_version:-no}
fi
if test -z "${build_root}" ; then
   build_root="${srcdir}/${signature_compiler}"
   case "$signature_compiler:$with_version" in
      *[[0-9]]:* | *:no) ;;
      *) build_root=${build_root}${compiler_version} ;;
   esac
   ncbi_cv_with_version=${with_version:-yes}
else
   : ${with_suffix:="no"}
fi


#### Release/Debug
case "${with_debug}:${with_optimization}" in
   no:*)
      release_debug=Release
      DEBUG_SFX=Release
      D_SFX=
      ;;
   yes:yes | :yes)
      release_debug=DebugOpt
      DEBUG_SFX=Debug
      D_SFX=d
      ;;
   *)
      release_debug=Debug
      DEBUG_SFX=Debug
      D_SFX=d
      ;;
esac

if test "${with_max_debug-no}" != "no"; then
   case "$NCBI_OLD_STATUS_DIR" in
      *MaxDebug* ) max_tag=Max ;;
      *Debug*    )             ;;
      *          ) max_tag=Max ;;
   esac
fi


#### Profiling; try to turn on both function weight and basic-block counting
if test "$with_profiling" = "yes" ; then
   prof_sfx="Prof"
   case "$compiler" in
      Compaq)    PFFLAGS="-pg" ;;
      GCC)       PFFLAGS="-pg" ;;
      ICC)       PFFLAGS="-p" ;;
      *Clang)    PFFLAGS="-pg" ;;
      KCC)       PFFLAGS="-pg" ;;
      MIPSpro73) PFFLAGS="" ;; # pixie(1) adds info at runtime
      MSVC)      PFFLAGS="/PROFILE" ;;
      VisualAge) PFFLAGS="-pg" ;;
      WorkShop*) PFFLAGS="-pg -xprofile=tcov" ;;
      *)         PFFLAGS="-p" ;; # Fairly standard; shouldn't rely on -pg
   esac
   CFLAGS="$CFLAGS $PFFLAGS"
   CXXFLAGS="$CXXFLAGS $PFFLAGS"
   LDFLAGS="$LDFLAGS $PFFLAGS"
   STRIP="@:" # Stripping may lose profiling info
else
   prof_sfx=
fi


#### Code coverage
if test "$with_code_coverage" = "yes"; then
   case "$compiler" in
      GCC | *Clang )
         COVFLAGS="--coverage"
         ;;
      * )
         AC_MSG_ERROR([--with-code-coverage not implemented for $compiler])
         ;;
   esac
   CFLAGS="$CFLAGS $COVFLAGS"
   CXXFLAGS="$CXXFLAGS $COVFLAGS"
   LDFLAGS="$LDFLAGS $COVFLAGS"
fi


#### Determine whether this is implicitly a 64-bit platform
AC_TYPE_SIZE_T
AC_CHECK_SIZEOF(size_t)
ac_cv_sizeof_size_t=`echo "$ac_cv_sizeof_size_t" | tr -d '\r'`
NCBI_PLATFORM_BITS=`expr 8 \* $ac_cv_sizeof_size_t`
AC_DEFINE_UNQUOTED(NCBI_PLATFORM_BITS, $NCBI_PLATFORM_BITS,
                   [Define to the architecture size.])
if test $NCBI_PLATFORM_BITS -eq 64; then
   bit64_sfx=64
fi

if test "$bit64_sfx" = 64 -o "$with_lfs" = "yes"; then
   NCBI_FEATURE(LFS)
fi


### Intel Thread Checker
if test "${with_tcheck=no}" != "no" ; then
   if test "${release_debug}${mt_sfx}" != "DebugMT" ; then
      AC_MSG_WARN([--with-tcheck is most likely to be effective in DebugMT builds.])
   fi
   if test "$compiler" = "ICC"; then
      case "$bit64_sfx" in
        64) tcbin=bin/32e ;;
        * ) tcbin=bin/32  ;;
      esac
      if test "$with_tcheck" != yes; then
         TCHECK_BIN=$with_tcheck/$tcbin
      fi
      AC_PATH_PROG(TCHECK_CL, tcheck_cl, [], $TCHECK_BIN:$PATH:$TCHECK_FALLBACK)
      if test -n "$TCHECK_CL"; then
         CFLAGS="$CFLAGS -tcheck -O0"
         CXXFLAGS="$CXXFLAGS -tcheck -O0"
         LDFLAGS="$LDFLAGS -tcheck -O0 -L`dirname $TCHECK_CL`"
      fi
   fi
   CPPFLAGS="$CPPFLAGS -DNCBI_TCHECK"
fi


#### Add "Release"/"Debug", "MT", "DLL", "64", "_p" suffixes to "${build_root}"
if test "$with_suffix" != "no" ; then
   build_root="${build_root}-${max_tag}${release_debug}${mt_sfx}${dll_sfx}${bit64_sfx}${prof_sfx}"
fi


#### Add full host specs to "${build_root}"
if test "$with_hostspec" = "yes" ; then
   build_root="${build_root}--${host}"
fi

if test -n "$with_build_root_sfx" ; then
   build_root=$build_root$with_build_root_sfx
fi

case "$host_os" in
   linux*)
      kver=`uname -r | sed -e 's/-.*//'`
      libcver=`ldd --version | awk 'NR == 1 { print $NF }'`
      verbose_host=$host_cpu-$host_vendor-linux$kver-gnu$libcver
      ;;
   *) verbose_host=$host ;;
esac

#### Overall configuration mode summary
signature_hostname=`(hostname || uname -n) 2>/dev/null \
    | sed 's/\..*//; s/-/_/g; 1q'`
signature="${signature_compiler}_${compiler_version}-${release_debug}${mt_sfx}${dll_sfx}${bit64_sfx}${prof_sfx}--${verbose_host}-${signature_hostname}"
AC_DEFINE_UNQUOTED(NCBI_SIGNATURE, "$signature",
   [Build signature: compiler-name '_' compiler-version '-' configuration
   '--' platform-name '-' hostname])


#### Check if there is "${build_root}" dir
test -d "${build_root}"  ||  mkdir -p "${build_root}"
test -d "${build_root}"  ||  AC_MSG_ERROR([Couldn't create ${build_root}])

#### Try to find a version of pwd that yields /net paths.
AC_PATH_PROG(AMQ, amq, [], $PATH:/usr/sbin:/sbin)
case "$AMQ" in
   */amq)
      AC_CACHE_CHECK([whether $AMQ -w works], ncbi_cv_prog_amq_w,
      [if $AMQ -w >/dev/null 2>&1; then
          ncbi_cv_prog_amq_w=yes
       else
          ncbi_cv_prog_amq_w=no
       fi])
      if test "$ncbi_cv_prog_amq_w" = yes; then
         smart_pwd="$AMQ -w"
      else
         smart_pwd=pwd
      fi
      ;;
   *)
      smart_pwd=pwd
      ;;
esac

#### Make "build_root" absolute
case "${build_root}" in
   /* ) ;;
   . )
      CDPATH=
      if test "${PWD}" != "" && test "`(cd ${PWD} ; sh -c pwd)`" = "`pwd`"  ;
      then
         build_root="$PWD"
      else
         NCBI_FIX_DIR(build_root)
      fi
   ;;
   *  ) NCBI_FIX_DIR(build_root) ;;
esac
if test -n "$with_fake_root"; then
   build_root=$with_fake_root/`basename $build_root`
fi


#### Set runpath (may depend on build root)
if test -n "$with_relative_runpath"; then
   if test "$with_runpath" = "no"; then
      AC_MSG_ERROR([incompatible options: --without-runpath and --with-relative-runpath=$with_relative_runpath])
   elif test -z "$origin"; then
      AC_MSG_ERROR([Do not know how to specify relative runpaths on $host])
   else
      rp=`echo "$origin/$with_relative_runpath" | \
          sed "s,:,:$origin/,g; s,/.:,:,g; s,/.\$,,"`
      with_runpath="$rp${with_runpath+:$with_runpath}"
   fi
fi

if test -z "$with_runpath"; then
   # Don't allow libdir values containing variable expansions,
   # including in particular the default "${exec_prefix}/lib"
   if test -n "$libdir"  &&  expr "$libdir" : '[[^$]]*$' >/dev/null; then
      with_runpath=$libdir
   elif test -n "$exec_prefix"  -a  "$exec_prefix" != "NONE" ; then
      with_runpath=$exec_prefix/lib
   elif test -n "$prefix"  -a  "$prefix" != "NONE" ; then
      with_runpath=$prefix/lib
   fi
fi

if   test "$with_runpath" = "no" ; then
   runpath=
   pure_runpath=
elif test -n "$with_runpath"  -a  "$with_runpath" != "yes" ; then
   root_base=`basename $build_root`
   pure_runpath=`echo "${with_runpath}" | sed -e "s/{}/$root_base/g"`
   runpath="${CONF_f_runpath}${pure_runpath}"
   case "$host_os:$compiler" in
    darwin* )
      # Needed for a few gui projects, including gbench_plugin_scan;
      # harmless elsewhere, since it only affects projects that indirectly
      # need one of these libraries.  (There seems to be no general
      # equivalent of -rpath-link.)
      for l in dbapi_driver gui_utils ncbi_xloader_genbank ncbi_xreader \
               ncbi_xreader_id1 ncbi_xreader_pubseqos; do
         ll=lib$l.dylib
         LDFLAGS="$LDFLAGS -dylib_file ${pure_runpath}/$ll:\$(libdir)/$ll"
      done
      ;;
    *:GCC )
      if `$CXX -print-prog-name=ld` --version 2>&1 | grep GNU >/dev/null; then
         runpath="$runpath -Wl,-rpath-link,\$(libdir)"
      fi
      ;;
    *:ICC )
      runpath="$runpath -Wl,-rpath-link,\$(libdir)"
      ;;
   esac
elif test "$with_runpath" = "yes"  -o  "$with_dll" != "no" ; then
   runpath="${CONF_f_runpath}\$(libdir)"
   pure_runpath='${build_root}/lib'
else
   runpath=
   pure_runpath=
fi
if test -z "$CONF_f_runpath" ; then
   # Drop the linker flag (since passing directory names doesn't work
   # so well), but keep pure_runpath for other uses.
   runpath=
fi


#### Linker command-line to build DLL (may depend on runpath)
has_dll_loadable="@# "
ALLOW_UNDEF=
FORBID_UNDEF=
case "$compiler" in
 GCC | ICC | *Clang)
   LINK_DLL="$LINK $ARCH_CFLAGS -shared -o" # possibly overridden below
   case "$host_os" in
      solaris* )
        # See http://realm.progsoc.uts.edu.au/~subtle/solaris28_link.html
        LINK_DLL="$LINK $ARCH_CFLAGS -shared -mimpure-text -o"
        FORBID_UNDEF="-Wl,-z,defs"
        ;;
      darwin* )
        # Per <https://fink.sourceforge.net/doc/porting/shared.php>, it was
        # historically necessary to build plugins as Mach-O bundles rather than
        # dynamic libraries.  That's not such a big deal on modern Mac OS X
        # versions, so the Toolkit now defaults to building only the latter.
        if test "$with_bundles" = yes; then
           has_dll_loadable=""
           AC_DEFINE(NCBI_USE_BUNDLES, 1,
              [Define to 1 if building plugins as bundles, as Mac OS X
               traditionally required.])
        fi
        if $CXX -v 2>&1 | egrep -q 'Apple|clang'; then
           LINK_DLL="$LINK $ARCH_CFLAGS -dynamiclib -install_name ${pure_runpath%%:*}/\$(XDLL) -o"
           LINK_LOADABLE="$LINK $ARCH_CFLAGS -bundle -o"
           ALLOW_UNDEF='-undefined suppress'
           FORBID_UNDEF='-undefined error'
        else
           LINK_DLL="$LINK $ARCH_CFLAGS -nostartfiles -Wl,-dynamic -Wl,-dylib -Wl,-install_name,${pure_runpath%%:*}/\$(XDLL) -o"
           LINK_LOADABLE="$LINK $ARCH_CFLAGS -nostartfiles -Wl,-dynamic -Wl,-bundle -Wl,-read_only_relocs,warning -lbundle1.o -o"
           ALLOW_UNDEF='-Wl,-undefined,suppress'
           FORBID_UNDEF='-Wl,-undefined,error'
        fi
        ;;
      linux* | *gnu* ) # | *bsd*
        case "$compiler:$compiler_version" in
           ICC:* )
             ncbi_cv_prog_cc_wl_no_asu=no
             LIBS="$LIBS -lc"
             C_LIBS="$C_LIBS -lc"
             ;;
           * )
             FORBID_UNDEF='-Wl,--no-undefined'
             ;;
        esac
        ;;
      irix* )
        FORBID_UNDEF='-Wl,-no_unresolved'
        ;;
      osf* )
        ALLOW_UNDEF='-Wl,-expect_unresolved,\*'
        FORBID_UNDEF='-Wl,-error_unresolved'
        ;;
   esac
   AC_CACHE_CHECK([whether $CC supports -Wl,--no-allow-shlib-undefined],
      ncbi_cv_prog_cc_wl_no_asu,
      [orig_LDFLAGS=$LDFLAGS
       LDFLAGS="$CXXFLAGS_DLL -shared -Wl,--no-allow-shlib-undefined $LDFLAGS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
          [ncbi_cv_prog_cc_wl_no_asu=yes], [ncbi_cv_prog_cc_wl_no_asu=no])
       LDFLAGS=$orig_LDFLAGS])
   if test "$ncbi_cv_prog_cc_wl_no_asu" = yes; then
      FORBID_UNDEF="$FORBID_UNDEF -Wl,--no-allow-shlib-undefined"
   fi
  ;;
 MIPSpro73 )
   LINK_DLL="$LINK $ARCH_CFLAGS -shared -o"
   FORBID_UNDEF="-no_unresolved"
   ;;
 Compaq )
   LINK_DLL="$LINK $ARCH_CFLAGS -shared -o"
   ALLOW_UNDEF='-expect_unresolved \*'
   FORBID_UNDEF='-error_unresolved'
   ;;
 WorkShop* )
   LINK_DLL="$LINK $ARCH_CFLAGS $MT_FLAG -G -h \$(XDLL) -o"
   FORBID_UNDEF="-z defs"
   ;;
 KCC )
   LINK_DLL="$LINK $ARCH_CFLAGS $MT_FLAG --soname \$(XDLL) -o"
   FORBID_UNDEF="-z defs"
   ;;
 VisualAge )
   # NOTE: --without-dll still recommended, as the linker doesn't seem
   # to support building shared libraries with undefined symbols.
   LINK_DLL="$LINK $ARCH_CFLAGS $MT_FLAG -qmkshrobj -o"
   # ALLOW_UNDEF="???"
   ;;
 * )
   if test "$with_dll" = "yes"  &&  test -z "$LINK_DLL" ; then
      AC_MSG_ERROR([Do not know how to build DLLs with compiler $CXX $compiler_ver])
   elif test -z "$LINK_DLL"; then
      with_dll=no
   fi
   ;;
esac

if test "$with_dll" = "no"; then # no DLLs whatsoever!
   DLL=
   FORCE_STATIC_LIB="LIB_OR_DLL = lib"
   APP_LIB_SETTING='$(STATIC_LIB)'
   APP_LIBS_SETTING='$(STATIC_LIBS)'
   if test "$with_bin_release" = "yes"; then
      CFLAGS="$CFLAGS $CFLAGS_DLL"
      CFLAGS_DLL=
      CXXFLAGS="$CXXFLAGS $CXXFLAGS_DLL"
      CXXFLAGS_DLL=
   fi
else
   FORCE_STATIC_LIB=
   APP_LIB_SETTING='$(LIB)'
   APP_LIBS_SETTING='$(LIBS)'
   NCBI_FEATURE(DLL)
   # Some shared libraries end up containing static libraries, so make
   # sure to use DLL flags for both, as such inclusion can otherwise
   # result in linker errors.
   DLL_LDFLAGS="$DLL_LDFLAGS $CXXFLAGS_DLL"
   CFLAGS="$CFLAGS $CFLAGS_DLL"
   CFLAGS_DLL=
   CXXFLAGS="$CXXFLAGS $CXXFLAGS_DLL"
   CXXFLAGS_DLL=
   AC_DEFINE(NCBI_DLL_SUPPORT, 1,
     [Define to 1 if building dynamic libraries at all
      (albeit not necessarily by default).])
   if test "$with_dll" = "yes"; then
      NCBI_FEATURE(DLL_BUILD)
      AC_DEFINE(NCBI_DLL_BUILD, 1,
                [Define to 1 if building dynamic libraries by default.])
      : ${with_plugin_auto_load=yes}
   fi
fi

if test "$with_plugin_auto_load" = yes; then
   AC_DEFINE(NCBI_PLUGIN_AUTO_LOAD, 1,
             [Define to 1 if the plugin manager should load DLLs by default.])
fi

# Make sure we have commands for both C and C++ preprocessors
AC_PROG_CPP
dnl AC_PROG_CXXCPP


#### Make "srcdir" absolute
case "${srcdir}" in
   /* ) ;;
   . )
      CDPATH=
      if test "${PWD}" != "" && test "`(cd ${PWD} ; sh -c pwd)`" = "`pwd`"  ;
      then
        srcdir="$PWD"
      else
        NCBI_FIX_DIR(srcdir)
      fi
   ;;
   * ) NCBI_FIX_DIR(srcdir) ;;
esac
real_srcdir=$srcdir
if test -n "$with_fake_root"; then
   srcdir=$build_root/..
fi


#### Ensure that all explicitly requested subtrees actually exist
NCBI_CHECK_SUBTREE(algo)
dnl NCBI_CHECK_SUBTREE(app)
if test "$with_app" = "no" ; then
   NoConfProjects="$NoConfProjects app"
fi

if test ! -f ${real_srcdir}/src/app/Makefile.in ; then
   if test "${with_app-no}" != "no" ; then
      AC_MSG_ERROR([--with-app:  APP sources are missing])
   fi
   with_app="no"
fi

dnl NCBI_CHECK_SUBTREE(bdb) # deferred until end, as --with-bdb does double duty
dnl NCBI_CHECK_SUBTREE(cgi) # --without-cgi deliberately unavailable for now
if test -f ${real_srcdir}/src/cgi/Makefile.in  -a \
        -d ${real_srcdir}/include/cgi; then
   NCBI_PROJECT(cgi)
else
   AC_MSG_WARN([CGI tree missing; some projects may fail to build.])
fi

NCBI_CHECK_SUBTREE(ctools)
NCBI_CHECK_SUBTREE(dbapi)
NCBI_CHECK_SUBTREE(gui)
NCBI_CHECK_SUBTREE(objects)
NCBI_CHECK_SUBTREE(serial)


#### Source, include, and build directories
ncbiconf="$build_root/inc/ncbiconf_unix.h"
ncbiconf_old="$build_root/inc/ncbiconf.h"
if test -f "$ncbiconf_old" -a ! -f "$ncbiconf"; then
   mv "$ncbiconf_old" "$ncbiconf"
fi
if test "$build_root" = "$srcdir" ; then
   builddir="$srcdir/src"
else
   builddir="$build_root/build"
fi
status_dir="$build_root/status"


#### Create build directories
mkdir -p "$builddir" "$build_root/lib" "$build_root/bin"


#### Check if the target directory already has a configured system in it
if test "$no_create" != "yes"  -a  -f "${ncbiconf}" ; then
   echo
   echo "There is already a built \"${ncbiconf}\"!"
   NCBI_CAUTION([Do you want to re-configure in \"${builddir}\" (at your own risk)?])
   echo
fi


#### Use right command shell in scripts and makefiles
script_shell="#! ${CONFIG_SHELL:=/bin/sh}"
make_shell="SHELL=${CONFIG_SHELL:=/bin/sh}"


#### Turn on compilation warnings and adjust
#### some compiler-specific flags and features

if test "$CONF_obj_ext"   = " " ;  then obj_ext="" ; else obj_ext="${CONF_obj_ext:=.o}" ; fi
if test "$CONF_lib_pre"   = " " ;  then lib_pre="" ; else lib_pre="${CONF_lib_pre:=lib}" ; fi
if test "$CONF_lib_l_pre" = " " ;  then lib_l_pre="" ; else lib_l_pre="${CONF_lib_l_pre:=-l}" ; fi
if test "$CONF_lib_ext"   = " " ;  then lib_ext="" ; else lib_ext="${CONF_lib_ext:=.a}" ; fi
if test "$CONF_dll_ext"   = " " ;  then dll_ext="" ; else dll_ext="${CONF_dll_ext:=.so}" ; fi
if test "$CONF_loadable_ext"  = " " ;  then loadable_ext="" ; else loadable_ext="${CONF_loadable_ext:=.so}" ; fi
if test "$CONF_lib_l_ext" = " " ;  then lib_l_ext="" ; else lib_l_ext="${CONF_lib_l_ext}" ; fi
if test "$CONF_exe_ext"   = " " ;  then exe_ext="" ; else exe_ext="${CONF_exe_ext}" ; fi
if test "$CONF_f_compile" = " " ;  then f_compile="" ; else f_compile="${CONF_f_compile:=-c }" ; fi
if test "$CONF_f_outobj"  = " " ;  then f_outobj="" ; else f_outobj="${CONF_f_outobj:=-o }" ; fi
if test "$CONF_f_outlib"  = " " ;  then f_outlib="" ; else f_outlib="${CONF_f_outlib}" ; fi
if test "$CONF_f_libpath" = " " ;  then f_libpath="" ; else f_libpath="${CONF_f_libpath:=-L}" ; fi
if test "$CONF_f_runpath" = " " ;  then f_runpath="" ; else f_runpath="${CONF_f_runpath:=$CONF_f_libpath}" ; fi
if test "$CONF_f_outexe"  = " " ;  then f_outexe="" ; else f_outexe="${CONF_f_outexe:=-o }" ; fi


BINCOPY="/bin/cp -p"
MAC_BINCOPY="/Developer/Tools/CpMac -p"
if test "$with_bincopy" != "yes"; then
   AC_CACHE_CHECK([whether cross-directory hard links work],
      ncbi_cv_sys_xdir_ln,
      [mkdir conftestdir
       touch conftestdir/conftestfile
       if ln -f conftestdir/conftestfile .; then
          ncbi_cv_sys_xdir_ln=yes
       else
          ncbi_cv_sys_xdir_ln=no
       fi
       rm -rf conftestdir conftestfile])
   if test "$ncbi_cv_sys_xdir_ln" = "yes"; then
      BINCOPY="/bin/ln -f"
      MAC_BINCOPY="\$(top_srcdir)/scripts/common/impl/ln_mac.sh"
   fi
fi
ifdiff="${CONFIG_SHELL} \$(top_srcdir)/scripts/common/impl/if_diff.sh"
if test "$OSTYPE" = "darwin" -a -x /Developer/Tools/CpMac; then
   BINCOPY="$ifdiff \"$MAC_BINCOPY\""
else
   BINCOPY="$ifdiff \"$BINCOPY\""
fi


#### Manage the debug-vs.-optimization flags ("--with(out)-(max-)debug",
#### "--with(out)-symbols", "--with(out)-optimization")
asan_sfx=''
if test "$compiler" != "MSVC" ; then
   if test "$with_debug" = "no" -o "$with_tcheck" != "no"; then
      CPPFLAGS="-DNDEBUG $CPPFLAGS"
   else
      CPPFLAGS="-D_DEBUG $CPPFLAGS"
   fi

   if test "${with_max_debug-no}" != "no"; then
      case "$compiler:$with_max_debug" in
         GCC:thread | *Clang:thread ) sanitize=-fsanitize=thread ;;
         GCC:yes | *Clang:yes ) sanitize=-fsanitize=address; asan_sfx=ASan ;;
         *:yes ) ;;
         * )
            AC_MSG_ERROR([--with-max-debug=$with_max_debug unimplemented for compiler $compiler])
            ;;
      esac
      case "$compiler" in
         GCC | *Clang )
            CPPFLAGS="-D_GLIBCXX_DEBUG $CPPFLAGS"
            CFLAGS="-fstack-check $sanitize $CFLAGS"
            CXXFLAGS="-fstack-check $sanitize $CXXFLAGS"
            LDFLAGS="$sanitize $LDFLAGS"
            ;;
         ICC ) 
            CPPFLAGS="-D_GLIBCXX_DEBUG $CPPFLAGS"
            CFLAGS="-debug all -fstack-security-check -ftrapuv $CFLAGS"
            CXXFLAGS="-debug all -fstack-security-check -ftrapuv $CXXFLAGS"
            ;;
         WorkShop* )
            CFLAGS="-xcheck=%all $CFLAGS"
            CXXFLAGS="-xcheck=%all $CXXFLAGS"
            ;;
      esac
      NCBI_FEATURE(MaxDebug)
   fi
changequote(, )dnl
   dbgrx1="$wsrx-g[^cx$wschars]*$wsrx"
   dbgrx2="$wsrx-gx*coff[0-9+]*$wsrx"
   optrx="$wsrx-x*O[0-9s]*$wsrx"
   NDEB_CFLAGS=`  echo " $CFLAGS "   | sed "s/$dbgrx1/ /g; s/$dbgrx2/ /g"`
   NDEB_CXXFLAGS=`echo " $CXXFLAGS " | sed "s/$dbgrx1/ /g; s/$dbgrx2/ /g"`
   NDEB_LDFLAGS=` echo " $LDFLAGS "  | sed "s/$dbgrx1/ /g; s/$dbgrx2/ /g"`
   if test "$with_symbols" = "no" ; then
      CFLAGS=$NDEB_CFLAGS
      CXXFLAGS=$NDEB_CXXFLAGS
      LDFLAGS=$NDEB_LDFLAGS
   else
      echo " $CFLAGS "  | $EGREP_Q "$dbgrx1|$dbgrx2" || CFLAGS="$CFLAGS -g"
      echo " $CXXFLAGS "| $EGREP_Q "$dbgrx1|$dbgrx2" || CXXFLAGS="$CXXFLAGS -g" 
      echo " $LDFLAGS " | $EGREP_Q "$dbgrx1|$dbgrx2" || LDFLAGS="$LDFLAGS -g"
      STRIP="@:"
      case "$compiler:$compiler_version" in
         GCC:* )
            # GCC 4.8 defaults to DWARF 4, which Totalview for one
            # can't handle; roll back to version 3 by default.
            echo " $USER_CFLAGS " | $EGREP_Q "$dbgrx1|$dbgrx2" || \
               CFLAGS="$NDEB_CFLAGS -gdwarf-3"
            echo " $USER_CXXFLAGS " | $EGREP_Q "$dbgrx1|$dbgrx2" || \
               CXXFLAGS="$NDEB_CXXFLAGS -gdwarf-3"
            echo " $USER_LDFLAGS " | $EGREP_Q "$dbgrx1|$dbgrx2" || \
               LDFLAGS="$NDEB_LDFLAGS -gdwarf-3"
            ;;
      esac
   fi

   NOPT_CFLAGS=`  echo " $CFLAGS "    | sed "s/$optrx/ /g"`
   NOPT_CXXFLAGS=`echo " $CXXFLAGS "  | sed "s/$optrx/ /g"`
   NOPT_LDFLAGS=` echo " $LDFLAGS "   | sed "s/$optrx/ /g"`
   if test "${with_tcheck-no}" != "no"; then
      # Suppress warnings when building with ICC.
      NOPT_CFLAGS="$NOPT_CFLAGS -O0"
      NOPT_CXXFLAGS="$NOPT_CXXFLAGS -O0"
      NOPT_LDFLAGS="$NOPT_LDFLAGS -O0"
   fi
   if test "$with_optimization" = "no" ; then
      CFLAGS="$NOPT_CFLAGS"
      CXXFLAGS="$NOPT_CXXFLAGS"
      LDFLAGS="$NOPT_LDFLAGS"
      FAST_CFLAGS="$CFLAGS"
      FAST_CXXFLAGS="$CXXFLAGS"
      FAST_LDFLAGS="$LDFLAGS"
   else
      if test "$GCC" = yes; then
         defoptim=-O2
      else
         defoptim=-O
      fi
      if echo " $CFLAGS "   | grep -v "$optrx" >/dev/null ; then
         CFLAGS="$CFLAGS $defoptim" ; fi
      if echo " $CXXFLAGS " | grep -v "$optrx" >/dev/null ; then
         CXXFLAGS="$CXXFLAGS $defoptim" ; fi
      if echo " $LDFLAGS "  | grep -v "$optrx" >/dev/null ; then
         LDFLAGS="$LDFLAGS $defoptim" ; fi
      if test "$skip_fast_flags" = yes ; then
         FAST_CFLAGS="$CFLAGS"
         FAST_CXXFLAGS="$CXXFLAGS"
         FAST_LDFLAGS="$LDFLAGS"
      else
         case "$compiler:$compiler_version" in
            ICC:[2-9]??? )
               NOPT_CFLAGS=`echo " $NOPT_CFLAGS" \
                            | sed -e 's/ -ffp-model=[^ ]*//'`
               NOPT_CXXFLAGS=`echo " $NOPT_CXXFLAGS" \
                              | sed -e 's/ -ffp-model=[^ ]*//'`
               # NOPT_LDFLAGS="$NOPT_LDFLAGS -fuse-ld=lld"
               ;;
         esac
         FAST_CFLAGS="$NOPT_CFLAGS $FAST_CFLAGS"
         FAST_CXXFLAGS="$NOPT_CXXFLAGS $FAST_CXXFLAGS"
         FAST_LDFLAGS="$NOPT_LDFLAGS $FAST_LDFLAGS"
      fi
   fi
changequote([, ])dnl
fi



### ------------------------------------------------------------------
### ------------------------------------------------------------------

### Check for header files.
AC_CHECK_HEADERS(iostream  iostream.h)
AC_CHECK_HEADERS(fstream   fstream.h)
AC_CHECK_HEADERS(strstream strstream.h strstrea.h)

AC_CHECK_HEADERS(inttypes.h limits limits.h)

### Check for the platform (very roughly)
AC_CHECK_HEADERS(unistd.h,  x_have_unistd="yes")
AC_CHECK_HEADERS(windows.h, x_have_windows="yes")

if test "$x_have_windows" = "yes" -a "x$host_os" != "xcygwin32" -a "x$host_os" != "xcygwin"; then
   AC_DEFINE(NCBI_OS_MSWIN, 1, [Define to 1 on Windows.])
   AC_DEFINE(NCBI_OS, "MSWIN", [Operating system name])
   NCBI_FEATURE(MSWin)
elif test "$x_have_unistd" = "yes" ; then
   AC_DEFINE(NCBI_OS_UNIX, 1,  [Define to 1 on Unix.])
   AC_DEFINE(NCBI_OS, "UNIX",  [Operating system name])

   UNIX_SRC='$(UNIX_SRC)'
   UNIX_USR_PROJ='$(UNIX_USR_PROJ)'
   NCBI_FEATURE(unix)
   NCBI_FEATURE(WinMain) # to accommodate a PTB-specific (ab)use of REQUIRES

   # Extra defines for variants we care about
   case "$OSTYPE" in
     aix)
        AC_DEFINE(NCBI_OS_AIX,     1, [Define to 1 on AIX.])
        NCBI_FEATURE(AIX)
        ;;
     *bsd)
        AC_DEFINE(NCBI_OS_BSD,     1, [Define to 1 on *BSD.])
        NCBI_FEATURE(BSD)
        ;;
     cygwin)
        AC_DEFINE(NCBI_OS_CYGWIN,  1, [Define to 1 on Cygwin.])
        NCBI_FEATURE(Cygwin)
        if test "$with_mt" = yes; then NCBI_FEATURE(CygwinMT); fi
        ;;
     darwin)
        AC_DEFINE(NCBI_OS_DARWIN,  1, [Define to 1 on Mac OS X.])
        NCBI_FEATURE(Darwin)
        if false; then NCBI_FEATURE(XCODE); fi
        ;;
     irix)
        AC_DEFINE(NCBI_OS_IRIX,    1, [Define to 1 on IRIX.])
        NCBI_FEATURE(IRIX)
        ;;
     linux)
        AC_DEFINE(NCBI_OS_LINUX,   1, [Define to 1 on Linux.])
        NCBI_FEATURE(Linux)
        ;;
     osf)
        AC_DEFINE(NCBI_OS_OSF1,    1, [Define to 1 on Tru64 Unix.])
        NCBI_FEATURE(OSF)
        ;;
     solaris)
        AC_DEFINE(NCBI_OS_SOLARIS, 1, [Define to 1 on Solaris.])
        NCBI_FEATURE(Solaris)
        ;;
   esac
else
dnl Classic Mac OS, no longer supported; the following line is
dnl commented out to avoid cluttering config.h.in.
dnl AC_DEFINE(NCBI_OS_MAC, 1, [Define to 1 on MacOS.])
   AC_DEFINE(NCBI_OS, "MAC", [Operating system name])
   NCBI_FEATURE(MacOS)
fi

case "$host_os" in
   cygwin* | osf* )
      AC_DEFINE(NETDB_REENTRANT, 1,
                [Define to 1 if the BSD-style netdb interface is reentrant.])
      ;;
esac

# AC_CHECK_TYPES is insufficient, as linking may still fail :-/
AC_CACHE_CHECK([for wstring], ac_cv_type_wstring_linkable,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <string>
         using std::wstring;]],
       [[wstring ws, ws2; ws.find_first_of(ws2);]])],
       [ac_cv_type_wstring_linkable=yes], [ac_cv_type_wstring_linkable=no])])
if test "$ac_cv_type_wstring_linkable" = "yes"; then
   AC_DEFINE(HAVE_WSTRING, 1,
      [Define to 1 if the system has the type `wstring'.])
fi

AC_CHECK_TYPES(socklen_t,,,[@%:@include <sys/types.h>
@%:@include <sys/socket.h>])
AC_CHECK_HEADERS(atomic.h cpuid.h dlfcn.h ieeefp.h poll.h sys/epoll.h \
                 sys/mount.h sys/sockio.h sys/statvfs.h sys/sysinfo.h \
                 sys/sysmacros.h sys/vfs.h x86intrin.h)
case "$host_os" in
   cygwin*) AC_CHECK_HEADERS(winternl.h) ;;
esac
# for FreeTDS
AC_CHECK_HEADERS(alloca.h arpa/inet.h dirent.h errno.h fcntl.h getopt.h \
                 langinfo.h libgen.h locale.h malloc.h net/inet/in.h netdb.h \
                 netinet/in.h netinet/tcp.h paths.h select.h signal.h \
                 stdbool.h stddef.h sys/eventfd.h sys/file.h sys/ioctl.h \
                 sys/param.h sys/resource.h sys/select.h sys/socket.h \
                 sys/time.h sys/wait.h valgrind/memcheck.h wchar.h)
AC_HEADER_TIME

AC_CHECK_HEADERS(cxxabi.h)
if test "$ac_cv_header_cxxabi_h" = "yes"; then
   AC_CHECK_DECL(abi::__cxa_demangle,
      [AC_DEFINE(HAVE_CXA_DEMANGLE, 1,
        [Define to 1 if `abi::__cxa_demangle' is available from <cxxabi.h>.])],
      [], [[@%:@include <cxxabi.h>]])
fi

orig_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $OPENMP_FLAGS"
AC_CHECK_HEADER(omp.h)
if test "$ac_cv_header_omp_h" = no; then
   if test "$with_openmp" = yes; then
      AC_MSG_ERROR([--with-openmp explicitly specified, but unavailable with $CC.])
   else
      OPENMP_FLAGS=
   fi
fi
CFLAGS=$orig_CFLAGS
dnl case $compiler:$host_os in
dnl    LLVMClang:linux* )
dnl       AC_CACHE_CHECK([whether $CC needs GCC's omp.h],
dnl          ncbi_cv_cc_lacks_omp_h,
dnl          [AC_COMPILE_IFELSE(
dnl             [AC_LANG_PROGRAM([@%:@include <omp.h>], [])],
dnl             ncbi_cv_cc_lacks_omp_h=no, ncbi_cv_cc_lacks_omp_h=yes)])
dnl       if test "$ncbi_cv_cc_lacks_omp_h" = yes; then
dnl          d=$(echo '@%:@include <omp.h>' | "$gccdir"/bin/gcc -E -M - | \
dnl              sed -ne 's, \([[^ ]]*\)/omp\.h,\1,p')
dnl          CPPFLAGS="-idirafter $d $CPPFLAGS"
dnl          $LN_S "$("$gccdir"/bin/gcc -print-file-name=libgomp.so)" \
dnl             "$build_root"/lib/libomp.so
dnl       fi
dnl       ;;
dnl esac

## gethostbyname_r() -- 2 different variants: 5-arg (Solaris), 6-arg (Linux).

AC_CACHE_CHECK([for gethostbyname_r], ncbi_cv_func_gethostbyname_r,
   [ncbi_cv_func_gethostbyname_r="no"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <netdb.h>]],
       [[
         void*           dummy = (void*) &gethostbyname_r;
         char            buf[1024];
         int             err;
         struct hostent* hp = 0;
         hp = gethostbyname_r("", hp, buf, sizeof(buf), &err);
       ]])],
       [
         ncbi_cv_func_gethostbyname_r="5"
       ]
    )
    if test "$ncbi_cv_func_gethostbyname_r" = "no" ; then
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <netdb.h>]],
       [[
         void*           dummy = (void*) &gethostbyname_r;
         char            buf[1024];
         int             err;
         struct hostent* hp = 0;
         err = gethostbyname_r("", hp, buf, sizeof(buf), &hp, &err);
       ]])],
       [
         ncbi_cv_func_gethostbyname_r="6"
       ]
    )
    fi])

if test "$ncbi_cv_func_gethostbyname_r" != "no" ; then
   AC_DEFINE_UNQUOTED(NCBI_HAVE_GETHOSTBYNAME_R, $ncbi_cv_func_gethostbyname_r,
    [If you have the `gethostbyname_r' function, define to the number of
     arguments it takes (normally 5 or 6).])
fi


## gethostbyaddr_r() -- 2 different variants: 7-arg (Solaris), 8-arg (Linux).

AC_CACHE_CHECK([for gethostbyaddr_r], ncbi_cv_func_gethostbyaddr_r,
   [ncbi_cv_func_gethostbyaddr_r="no"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[
         @%:@include <netdb.h>
         @%:@include <sys/types.h>
         @%:@include <sys/socket.h>
       ]],
       [[
         void* dummy = (void*) &gethostbyaddr_r;
         char            buf[1024];
         int             err;
         unsigned int    host;
         struct hostent* hp = 0;
         hp = gethostbyaddr_r((char *) &host, sizeof(host), AF_INET,
                              hp, buf, sizeof(buf), &err);
       ]])],
       [
         ncbi_cv_func_gethostbyaddr_r="7"
       ]
    )
    if test "$ncbi_cv_func_gethostbyaddr_r" = "no" ; then
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[
         @%:@include <netdb.h>
         @%:@include <sys/types.h>
         @%:@include <sys/socket.h>
       ]],
       [[
         void* dummy = (void*) &gethostbyaddr_r;
         char            buf[1024];
         int             err;
         unsigned int    host;
         struct hostent* hp = 0;
         int res = gethostbyaddr_r((char *) &host, sizeof(host), AF_INET,
                                   hp, buf, sizeof(buf), &hp, &err);
       ]])],
       [
         ncbi_cv_func_gethostbyaddr_r="8"
       ]
    )
    fi])

if test "$ncbi_cv_func_gethostbyaddr_r" != "no" ; then
   AC_DEFINE_UNQUOTED(NCBI_HAVE_GETHOSTBYADDR_R, $ncbi_cv_func_gethostbyaddr_r,
    [If you have the `gethostbyaddr_r' function, define to the number of
     arguments it takes (normally 7 or 8).])
fi


## getservbyname_r() -- 2 different variants: 5-arg (Solaris), 6-arg (Linux).

AC_CACHE_CHECK([for getservbyname_r], ncbi_cv_func_getservbyname_r,
   [ncbi_cv_func_getservbyname_r="no"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <netdb.h>]],
       [[
         void*           dummy = (void*) &getservbyname_r;
         char            buf[1024];
         int             err;
         struct servent* sp = 0;
         sp = getservbyname_r("", "", sp, buf, sizeof(buf));
       ]])],
       [
         ncbi_cv_func_getservbyname_r="5"
       ]
    )
    if test "$ncbi_cv_func_getservbyname_r" = "no" ; then
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <netdb.h>]],
       [[
         void*           dummy = (void*) &getservbyname_r;
         char            buf[1024];
         int             err;
         struct servent* sp = 0;
         err = getservbyname_r("", "", sp, buf, sizeof(buf), &sp);
       ]])],
       [
         ncbi_cv_func_getservbyname_r="6"
       ]
    )
    fi])

if test "$ncbi_cv_func_getservbyname_r" != "no" ; then
   AC_DEFINE_UNQUOTED(NCBI_HAVE_GETSERVBYNAME_R, $ncbi_cv_func_getservbyname_r,
    [If you have the `getservbyname_r' function, define to the number of
     arguments it takes (normally 5 or 6).])
fi

## getpwuid_r() -- 2 major variants: 4-arg, 5-arg (POSIX).
## (Alternate 4-arg interface ignored due to rarity.)

AC_CACHE_CHECK([for getpwuid_r], ncbi_cv_func_getpwuid_r,
   [ncbi_cv_func_getpwuid_r="no"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <unistd.h>
         @%:@include <pwd.h>]],
       [[struct passwd bpw;
         char buf[1024];
         char *dir = getpwuid_r(getuid(), &bpw, buf, sizeof(buf))->pw_dir;
       ]])],
       [ncbi_cv_func_getpwuid_r=4])
    if test "$ncbi_cv_func_getpwuid_r" = "no" ; then
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <unistd.h>
         @%:@include <pwd.h>]],
       [[struct passwd *pw, bpw;
         char buf[1024];
         getpwuid_r(getuid(), &bpw, buf, sizeof(buf), &pw);
       ]])],
       [ncbi_cv_func_getpwuid_r=5])
    fi])

if test "$ncbi_cv_func_getpwuid_r" != "no" ; then
   AC_DEFINE_UNQUOTED(NCBI_HAVE_GETPWUID_R, $ncbi_cv_func_getpwuid_r,
    [If you have the `getpwuid_r' function, define to the number of
     arguments it takes (normally 4 or 5).])
fi

# Perform a full-fledged check in C++ to be sure of an actual declaration.
# Accommodate the old Solaris interface that returns char* rather than int. :-/
AC_CACHE_CHECK([for getlogin_r], ncbi_cv_func_getlogin_r,
   [ncbi_cv_func_getlogin_r="no"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <unistd.h>]],
       [[char buf[64]; /* return */ getlogin_r(buf, 64);]])],
       [ncbi_cv_func_getlogin_r=yes], [ncbi_cv_func_getlogin_r=no])])
if test $ncbi_cv_func_getlogin_r = yes; then
   AC_DEFINE(HAVE_GETLOGIN_R, 1,
      [Define to 1 if you have the `getlogin_r' function])
fi

AC_LANG_PUSH(C)
# some of these can lose in C++ due to the way autoconf works
AC_CHECK_FUNCS(localtime_r pthread_setconcurrency pthread_atfork)
if test "$ac_cv_func_localtime_r" = "yes" ; then
   AC_CACHE_CHECK(return type of localtime_r, ac_cv_func_which_localtime_r,
      [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM(
             [[@%:@include <unistd.h>
               @%:@include <time.h>]],
             [[struct tm mytm;
               time_t t;
               int y = localtime_r(&t, &mytm)->tm_year;]])],
          ac_cv_func_which_localtime_r=struct,
          ac_cv_func_which_localtime_r=int)])
   if test $ac_cv_func_which_localtime_r = struct; then
      AC_DEFINE(HAVE_FUNC_LOCALTIME_R_TM, 1,
         [Define to 1 if your localtime_r returns a struct tm*.])
   else
     AC_DEFINE(HAVE_FUNC_LOCALTIME_R_INT, 1,
        [Define to 1 if your localtime_r returns a int.])
   fi
fi

AC_CACHE_CHECK([whether pthread mutexes are available],
   ncbi_cv_func_pthread_mutex,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <pthread.h>
         pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;]],
       [[pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex);]])],
      [ncbi_cv_func_pthread_mutex=yes], [ncbi_cv_func_pthread_mutex=no])])
if test $ncbi_cv_func_pthread_mutex=yes; then
   AC_DEFINE(HAVE_PTHREAD_MUTEX, 1,
      [Define to 1 if pthread mutexes are available.])
fi


### Check for other standard library functions

AC_FUNC_VPRINTF
AC_CHECK_FUNCS(accept4 alarm asprintf atoll basename dbopen daemon euidaccess \
               eventfd execvpe fseeko fstat getgrouplist \
               gethrtime getopt getpagesize \
               getpass getpassphrase getpwuid getrusage gettimeofday getuid \
               lchown lutimes malloc_options memrchr nl_langinfo pipe2 poll \
               putenv readpassphrase readv select setenv setitimer setrlimit \
               snprintf statfs statvfs strcasecmp strdup strlcat strlcpy \
               strndup strnlen strsep strtok_r sysmp timegm usleep utimes \
               vasprintf vsnprintf writev)
AC_LANG_POP(C)

AC_TYPE_SIGNAL
test "$ac_cv_func_select" = yes  ||  ncbi_cv_func_select_updates_timeout=no
AC_CACHE_CHECK([whether select updates the timeout when interrupted],
               ncbi_cv_func_select_updates_timeout,
   [AC_RUN_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <signal.h>
         @%:@include <sys/types.h>
         @%:@ifdef HAVE_SYS_SELECT_H
         @%:@  include <sys/select.h>
         @%:@endif
         @%:@ifdef HAVE_SYS_TIME_H
         @%:@  include <sys/time.h>
         @%:@endif
         @%:@ifdef HAVE_UNISTD_H
         @%:@  include <unistd.h>
         @%:@endif
         RETSIGTYPE handler(int sig) { alarm(0); }]],
       [[struct timeval timeout = { 5, 0 };
         signal(SIGALRM, &handler);
         alarm(1);
         select(0, NULL, NULL, NULL, &timeout);
         return timeout.tv_sec == 5;]])],
       [ncbi_cv_func_select_updates_timeout=yes],
       [ncbi_cv_func_select_updates_timeout=no],
       [case "$host_os" in
          linux) ncbi_cv_func_select_updates_timeout=yes ;;
          *) ncbi_cv_func_select_updates_timeout=no ;;
        esac])])
if test "$ncbi_cv_func_select_updates_timeout" = yes; then
   AC_DEFINE(SELECT_UPDATES_TIMEOUT, 1,
      [Define to 1 if the `select' function updates its timeout when
       interrupted by a signal.])
fi

# We want the program to return 0, which is *false* in C.  Also, since
# use of lowercase seems to be customary if not universal, the default
# is yes when cross-compiling; anyone cross-compiling for exceptional
# platforms can set ncbi_cv_func_strcasecmp_lc=no in config.site.
if test "$ac_cv_func_strcasecmp" = yes; then
   AC_CACHE_CHECK([whether strcasecmp treats letters as lowercase],
                  ncbi_cv_func_strcasecmp_lc,
      [AC_RUN_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <string.h>]],
          [[return strcasecmp("A", "_") <= 0;]])],
          [ncbi_cv_func_strcasecmp_lc=yes], [ncbi_cv_func_strcasecmp_lc=no],
          [ncbi_cv_func_strcasecmp_lc=yes])])
   if test "$ncbi_cv_func_strcasecmp_lc" = yes; then
      AC_DEFINE(HAVE_STRCASECMP_LC, 1,
                [Define to 1 if strcasecmp treats letters as lowercase.])
   fi
fi

AC_CACHE_CHECK([for Linux-like sysinfo with 1 arg], ncbi_cv_func_sysinfo_1,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <sys/sysinfo.h>]],
       [[
         void* dummy = (void*) &sysinfo;
         struct sysinfo* info = 0;
         int retval = sysinfo(info);
       ]])], [ncbi_cv_func_sysinfo_1=yes], [ncbi_cv_func_sysinfo_1=no])])

if test "$ncbi_cv_func_sysinfo_1" = yes; then
   AC_DEFINE(HAVE_SYSINFO_1, 1,
             [Define to 1 if Linux-like 1-arg sysinfo exists.])
fi

dnl Too much overkill, and now wants getloadavg.c to exist.
dnl AC_FUNC_GETLOADAVG
AC_CHECK_FUNCS(getloadavg)

## readdir_r() -- 2 different variants: 2-arg (trad. Solaris), 3-arg (POSIX).

AC_CACHE_CHECK([for readdir_r], ncbi_cv_func_readdir_r,
   [ncbi_cv_func_readdir_r="no"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <dirent.h>]],
       [[DIR* dir; struct dirent* entry; readdir_r(dir, entry, &entry);]])],
       [ncbi_cv_func_readdir_r=3])
    if test "$ncbi_cv_func_readdir_r" = "no" ; then
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <dirent.h>]],
       [[DIR* dir; struct dirent* entry; readdir_r(dir, entry);]])],
       [ncbi_cv_func_readdir_r=2])
    fi])

if test "$ncbi_cv_func_readdir_r" != "no" ; then
   AC_DEFINE_UNQUOTED(NCBI_HAVE_READDIR_R, $ncbi_cv_func_readdir_r,
    [If you have the `readdir_r' function, define to the number of
     arguments it takes (normally 2 or 3).])
fi

AC_CACHE_CHECK([whether stdio supports locking], ncbi_cv_c_stdio_locked,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM(
      [[@%:@include <stdio.h>]],
      [[int c;
        flockfile(stdin);
        c = getc_unlocked(stdin);
        funlockfile(stdin);]])],
      [ncbi_cv_c_stdio_locked=yes], [ncbi_cv_c_stdio_locked=no])])
if test "$ncbi_cv_c_stdio_locked" = yes; then
   AC_DEFINE(NCBI_HAVE_STDIO_LOCKED, 1,
      [Define to 1 if stdio supports locking.])
fi

### Check for typedefs, structures, and compiler features.
AC_C_CONST

### Check for C standard types and sizes
AC_C_BIGENDIAN
AC_C_CHAR_UNSIGNED
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(float)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long double)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(void*)
AC_CHECK_SIZEOF(wchar_t, [], [@%:@include <wchar.h>])
AC_CHECK_SIZEOF(__int64)
AC_CHECK_TYPES([intptr_t, uintptr_t])

AC_CHECK_MEMBER(struct sockaddr_in.sin_len,
   [AC_DEFINE(HAVE_SIN_LEN, 1,
      [Define to 1 if `sin_len' is a member of `struct sockaddr_in'.])],
   [], [@%:@include <sys/types.h>
        @%:@include <netinet/in.h>])

AC_CHECK_MEMBERS([struct tm.tm_zone, struct tm.__tm_zone], [], [],
   [@%:@include <time.h>])


AC_CACHE_CHECK([whether function prototypes can use throw(...)],
   ncbi_cv_cxx_throw_spec,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[template <class T> inline int test_throw_spec(const T&) throw() {
          return 0;
       }]],
       [[return test_throw_spec(123);]])],
       [ncbi_cv_cxx_throw_spec=yes], [ncbi_cv_cxx_throw_spec=no])])
if test "$ncbi_cv_cxx_throw_spec" = yes; then
   AC_DEFINE(NCBI_USE_THROW_SPEC, 1,
             [Define to 1 if prototypes can use exception specifications.])
fi


AC_CACHE_CHECK([for ios(_base)::register_callback],
   ncbi_cv_func_ios_register_callback,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <iostream>]],
       [[std::cout.register_callback(0, std::ios::erase_event);]])],
       [ncbi_cv_func_ios_register_callback=yes],
       [ncbi_cv_func_ios_register_callback=no])])
if test "$ncbi_cv_func_ios_register_callback" = yes; then
   AC_DEFINE(HAVE_IOS_REGISTER_CALLBACK, 1,
             [Define to 1 if you have `ios(_base)::register_callback'.])
fi


AC_CACHE_CHECK([for SysV semaphores], ncbi_cv_sys_semaphores,
   AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <sys/types.h>
@%:@include <sys/sem.h>],
      [struct sembuf buf; int id = semget(0x1234, 0, IPC_CREAT);
       buf.sem_op = SEM_UNDO;])],
      [ncbi_cv_sys_semaphores=yes], [ncbi_cv_sys_semaphores=no]))
if test "$ncbi_cv_sys_semaphores" = yes; then
   AC_DEFINE(HAVE_SYSV_SEMAPHORES, 1,
             [Define to 1 if you have SysV semaphores.])
fi

AC_CHECK_TYPE([union semun],
   AC_DEFINE(HAVE_SEMUN, 1, [Define to 1 if you have `union semun'.]),
   [], [@%:@include <sys/types.h>
@%:@include <sys/sem.h>])


AC_CACHE_CHECK([which way the stack grows], ncbi_cv_sys_stack_dir,
   [AC_RUN_IFELSE([AC_LANG_PROGRAM(
        [[ int f(int* p) { int i; return (&i < p) ? 1 : 0; } ]],
        [[ int p; return f(&p); ]])],
        [ncbi_cv_sys_stack_dir=up], [ncbi_cv_sys_stack_dir=down],
        [ncbi_cv_sys_stack_dir="unknown (cross-compiling)"])])
case "$ncbi_cv_sys_stack_dir" in
 up)   AC_DEFINE(STACK_GROWS_UP,   1, [Define to 1 if the stack grows up.])  ;;
 down) AC_DEFINE(STACK_GROWS_DOWN, 1, [Define to 1 if the stack grows down.]);;
esac

AC_LANG_PUSH(C)

AC_CACHE_CHECK([whether the preprocessor supports C99-style variadic macros],
   ncbi_cv_cpp_std_varargs,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@define foo(...) 1
         @%:@if foo(x,y,z) != 1
         @%:@error failed
         @%:@endif]], [])],
       [ncbi_cv_cpp_std_varargs=yes], [ncbi_cv_cpp_std_varargs=no])])
if test "$ncbi_cv_cpp_std_varargs" = yes; then
   AC_DEFINE(HAVE_CPP_STD_VARARGS, 1,
      [Define to 1 if the preprocessor supports C99-style variadic macros.])
fi

AC_CACHE_CHECK([whether the preprocessor supports GNU-style variadic macros],
   ncbi_cv_cpp_gnu_varargs,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[@%:@define foo(args...) 1
         @%:@if foo(x,y,z) != 1
         @%:@error failed
         @%:@endif]], [])],
       [ncbi_cv_cpp_gnu_varargs=yes], [ncbi_cv_cpp_gnu_varargs=no])])
if test "$ncbi_cv_cpp_gnu_varargs" = yes; then
   AC_DEFINE(HAVE_CPP_GNU_VARARGS, 1,
      [Define to 1 if the preprocessor supports GNU-style variadic macros.])
fi

AC_LANG_POP(C)

# Avoid using unsupported (and noisily ignored) attributes.
case "$compiler:$compiler_version" in
   VisualAge:* | WorkShop* )
      ncbi_cv_c_forceinline=inline
      ;;
esac

AC_LANG_PUSH(C)
AC_CACHE_CHECK([how to force inlining],
   ncbi_cv_c_forceinline,
   [ncbi_cv_c_forceinline=no
    for fi in __always_inline "inline __attribute__((always_inline))" \
       forceinline __forceinline__ __forceinline inline __inline__; do
       test "$ncbi_cv_c_forceinline" = "no" || break
       AC_COMPILE_IFELSE([AC_LANG_SOURCE([$fi int f(void) { return 0; }])],
          [ncbi_cv_c_forceinline=$fi], [])
    done])
forceinline=$ncbi_cv_c_forceinline
test "$forceinline" = "no"  &&  forceinline=""
AC_DEFINE_UNQUOTED(NCBI_FORCEINLINE, $forceinline,
   [Define to whatever syntax your compiler supports for marking functions
    as to be inlined even if they might not otherwise be.])

case "$compiler:$compiler_version $CFLAGS $CXXFLAGS" in
   GCC:*\ *\ -fvisibility* | ICC:*\ -fvisibility* | *Clang:*\ -fvisibility*) ;;
   * ) ncbi_cv_c_attribute_visibility_default=unnecessary ;;
esac

AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("default")))],
   ncbi_cv_c_attribute_visibility_default,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[__attribute__((visibility("default"))) void f(void); void f(void) {}]],
       [[f();]])],
      [ncbi_cv_c_attribute_visibility_default=yes],
      [ncbi_cv_c_attribute_visibility_default=no])])
if test $ncbi_cv_c_attribute_visibility_default = yes; then
   AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY_DEFAULT, 1,
      [Define to 1 if your compiler supports __attribute__((visibility("default")))])
fi

AC_CACHE_CHECK([whether the C compiler supports C99 restrict],
   ncbi_cv_c_restrict,
   [ncbi_cv_c_restrict=no
    for restrict in __restrict__ __restrict restrict; do
       test "$ncbi_cv_c_restrict" = "no" || break
       AC_COMPILE_IFELSE([AC_LANG_SOURCE([void f(int * $restrict p);])],
          [ncbi_cv_c_restrict=$restrict], [])
    done])
restrict=$ncbi_cv_c_restrict
test "$restrict" = "no"  &&  restrict=""
AC_DEFINE_UNQUOTED(NCBI_RESTRICT_C, $restrict,
   [Define to whatever syntax, if any, your C compiler supports for marking
    pointers as restricted in the C99 sense.])
if test -n "$restrict"; then
   AC_DEFINE(HAVE_RESTRICT_C, 1,
      [Define to 1 if your C compiler supports some variant of the C99
       `restrict' keyword.])
fi
AC_LANG_POP(C)

AC_CACHE_CHECK([whether the C++ compiler supports C99 restrict],
   ncbi_cv_cxx_restrict,
   [ncbi_cv_cxx_restrict=no
    for restrict in __restrict__ __restrict restrict; do
       test "$ncbi_cv_cxx_restrict" = "no" || break
       AC_COMPILE_IFELSE([AC_LANG_SOURCE([void f(int * $restrict p);])],
          [ncbi_cv_cxx_restrict=$restrict], [])
    done])
restrict=$ncbi_cv_cxx_restrict
test "$restrict" = "no"  &&  restrict=""
AC_DEFINE_UNQUOTED(NCBI_RESTRICT_CXX, $restrict,
   [Define to whatever syntax, if any, your C++ compiler supports for marking
    pointers as restricted in the C99 sense.])
if test -n "$restrict"; then
   AC_DEFINE(HAVE_RESTRICT_CXX, 1,
      [Define to 1 if your C++ compiler supports some variant of the C99
       `restrict' keyword.])
fi

AC_CACHE_CHECK([syntax for declaring thread-local variables],
   ncbi_cv_c_tls_var,
   [ncbi_cv_c_tls_var=none
    for tls_var in __thread '__declspec(thread)' _Thread_local; do
       test "$ncbi_cv_c_tls_var" = "none" || break
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$tls_var int i;],
          [static $tls_var int j;])],
          [ncbi_cv_c_tls_var=$tls_var], [])
    done])
tls_var=$ncbi_cv_c_tls_var
if test "$tls_var" != "none"; then
   AC_DEFINE_UNQUOTED(NCBI_TLS_VAR, $tls_var,
      [Define to whatever syntax your compiler supports for declaring
       thread-local variables, or leave undefined if it doesn't.])
fi

# for FreeTDS
AC_CACHE_CHECK([whether FIONBIO requires BSD_COMP to be defined],
   ncbi_cv_decl_fionbio_needs_bsd_comp,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[ @%:@include <sys/types.h>
          @%:@include <sys/ioctl.h> ]],
       [[ int request = FIONBIO; ]])],
       [ncbi_cv_decl_fionbio_needs_bsd_comp=no],
       [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
           [[ @%:@define BSD_COMP 1
              @%:@include <sys/types.h>
              @%:@include <sys/ioctl.h> ]],
           [[ int request = FIONBIO; ]])],
           [ncbi_cv_decl_fionbio_needs_bsd_comp=yes],
           [ncbi_cv_decl_fionbio_needs_bsd_comp="never defined at all"])])])
if test "$ncbi_cv_decl_fionbio_needs_bsd_comp" = yes; then
   AC_DEFINE(BSD_COMP, 1,
             [Define to 1 if necessary to get FIONBIO (e.g., on Solaris)])
fi

AC_CACHE_CHECK([whether INADDR_NONE is defined], ncbi_cv_decl_inaddr_none,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
       [[
         @%:@ifdef HAVE_SYS_TYPES_H
         @%:@include <sys/types.h>
         @%:@endif
         @%:@ifdef HAVE_SYS_SOCKET_H
         @%:@include <sys/socket.h>
         @%:@endif
         @%:@ifdef HAVE_NETINET_IN_H
         @%:@include <netinet/in.h>
         @%:@endif
         @%:@ifdef HAVE_ARPA_INET_H
         @%:@include <arpa/inet.h>
         @%:@endif
       ]],
       [[ unsigned long addr = INADDR_NONE; ]])],
       [ncbi_cv_decl_inaddr_none=yes], [ncbi_cv_decl_inaddr_none=no])])
if test "$ncbi_cv_decl_inaddr_none" != yes; then
   AC_DEFINE(INADDR_NONE, 0xffffffff,
             [Define to 0xffffffff if your operating system doesn't.])
fi

AC_CACHE_CHECK([whether unaligned reads are permissible],
               ncbi_cv_sys_unaligned_reads,
   [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ @%:@include <stdio.h> ]],
       [[ unsigned int a[2] = { 0x01234567, 0x89abcdef };
          fprintf(stderr, "%x\n", *(unsigned int*)((char*)a + 1)); ]])],
       [ncbi_cv_sys_unaligned_reads=yes],
       [ncbi_cv_sys_unaligned_reads=no],
       [case "$host_cpu" in
          i?86|x86_64|powerpc*|ppc*) ncbi_cv_sys_unaligned_reads=yes ;;
          *)                         ncbi_cv_sys_unaligned_reads=no  ;;
        esac])])
if test "$ncbi_cv_sys_unaligned_reads" = yes; then
   AC_DEFINE(HAVE_UNALIGNED_READS, 1,
             [Define to 1 if your system permits reading integers from
              unaligned addresses.])
fi

AC_LANG_PUSH(C)
orig_CFLAGS=$CFLAGS

AC_CACHE_CHECK([whether $CC supports SIMD vector arithmetic],
               ncbi_cv_cc_vector_math,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
         [typedef int TVector __attribute__((vector_size(16)));
          TVector f(TVector v1, TVector v2) { return v1 ^ v2; }],
         [TVector v1, v2, v3;  v3 = f(v1, v2);])],
      [ncbi_cv_cc_vector_math=yes], [ncbi_cv_cc_vector_math=no])])
if test "$ncbi_cv_cc_vector_math" = yes; then
   AC_DEFINE(HAVE_VECTOR_MATH, 1,
      [Define to 1 if your C compiler supports SIMD vector calculations.])
fi

AC_CACHE_CHECK([whether $CC supports -funsafe-math-optimizations],
               ncbi_cv_cc_unsafe_math,
   [CFLAGS="$orig_CFLAGS -funsafe-math-optimizations"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
       [ncbi_cv_cc_unsafe_math=yes], [ncbi_cv_cc_unsafe_math=no])])

AC_CACHE_CHECK([whether $CC supports -msse4.1], ncbi_cv_cc_sse4_1,
   [CFLAGS="$orig_CFLAGS -msse4.1"
    AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <emmintrin.h>],
          [double v __attribute__((__vector_size__(16)));
           __builtin_ia32_shufpd(v, v, 1);])],
       [ncbi_cv_cc_sse4_1=yes], [ncbi_cv_cc_sse4_1=no])])

AC_CACHE_CHECK([whether $CC supports -maes], ncbi_cv_cc_aes,
   [CFLAGS="$orig_CFLAGS -maes"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
          [@%:@include <wmmintrin.h>
           typedef long long TAESVec __attribute__((__vector_size__(16)));
           TAESVec f(TAESVec v, TAESVec w) {
              return __builtin_ia32_aesdec128(v, w);
           }], [])],
       [ncbi_cv_cc_aes=yes], [ncbi_cv_cc_aes=no])])

case "$compiler:$compiler_version" in
 ICC:??? | ICC:1??? )
   # Pre-(20)21 ICC noisily ignores this flag, so explicitly blacklist it.
   ncbi_cv_cc_fdiagnostics_color_always=no
   ;;
esac
AC_CACHE_CHECK([whether $CC supports -fdiagnostics-color=always],
   ncbi_cv_cc_fdiagnostics_color_always,
   [CFLAGS="$orig_CFLAGS -fdiagnostics-color=always"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
       [ncbi_cv_cc_fdiagnostics_color_always=yes],
       [ncbi_cv_cc_fdiagnostics_color_always=no])])
if test $ncbi_cv_cc_fdiagnostics_color_always = yes; then
   COLOR_DIAGNOSTICS=-fdiagnostics-color=always
else
   COLOR_DIAGNOSTICS=
fi

CFLAGS=$orig_CFLAGS
AC_LANG_POP(C)

if test $ncbi_cv_cc_unsafe_math = yes; then
   UNSAFE_MATH_FLAG=-funsafe-math-optimizations
else
   UNSAFE_MATH_FLAG=
fi

if test $ncbi_cv_cc_sse4_1 = yes; then
   SSE4_1_FLAG=-msse4.1
else
   SSE4_1_FLAG=
fi

if test $ncbi_cv_cc_sse4_1 = yes -a $ncbi_cv_cc_aes = yes; then
   AES_FLAG=-maes
else
   AES_FLAG=
fi

AC_CACHE_CHECK([whether $CXX supports __builtin_bswap32],
   ncbi_cv_cxx_builtin_bswap32,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
                       [[int i = 0x01234567; return __builtin_bswap32(i);]])],
       [ncbi_cv_cxx_builtin_bswap32=yes], [ncbi_cv_cxx_builtin_bswap32=no])])
if test $ncbi_cv_cxx_builtin_bswap32 = yes; then
   AC_DEFINE(HAVE_BUILTIN_BSWAP, 1,
      [Define to 1 if the C++ compiler supports __builtin_bswap32.])
fi

AC_CACHE_CHECK([whether $CXX supports __builtin_expect],
   ncbi_cv_cxx_builtin_expect,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
                       [[int i = 0;  return __builtin_expect(i, 0);]])],
       [ncbi_cv_cxx_builtin_expect=yes], [ncbi_cv_cxx_builtin_expect=no])])
if test $ncbi_cv_cxx_builtin_expect = yes; then
   AC_DEFINE(HAVE_BUILTIN_EXPECT, 1,
      [Define to 1 if the C++ compiler supports __builtin_expect.])
fi

### Check for the availability of other packages
### --------------------------------------------


AC_MSG_CHECKING([whether in-house NCBI resources are available])
if test -n "$orig_NCBI" -a -f "$orig_NCBI/.ncbirc" \
    -a \( -d /am/ncbiapdata/test_data -o -d /Volumes/ncbiapdata/test_data \)
then
   NCBI_FEATURE(in-house-resources)
   if test -d /am/ncbiapdata/test_data/traces04 \
      -o -d /Volumes/ncbiapdata/test_data/traces04; then
       NCBI_FEATURE(full-test-data)
   fi
   if test -d "`sed -ne 's/^[[Bb][Ll][Aa][Ss][Tt][Dd][Bb]] *= *//p' \
                $orig_NCBI/.ncbirc 2>/dev/null`"; then
       NCBI_FEATURE(full-blastdb)
   fi
   AC_MSG_RESULT(yes)
else
   AC_MSG_RESULT(no)
fi

### Common-use system and miscellaneous libs
if test -z "${NETWORK_LIBS+set}"; then
   AC_SEARCH_LIBS(gethostbyname, [nsl],
      [test "x$ac_cv_search_gethostbyname" = "xnone required" \
       || libnsl=$ac_cv_search_gethostbyname],
      [libnsl=])
   AC_SEARCH_LIBS(connect, [socket],
      [test "x$ac_cv_search_connect" = "xnone required" \
       || NETWORK_LIBS="$ac_cv_search_connect $libnsl"],
      [NETWORK_LIBS=$libnsl])
fi
AC_CACHE_CHECK([for res_search in -lresolv], ac_cv_lib_resolv_res_search,
   [orig_LIBS=$LIBS
    LIBS="-lresolv $NETWORK_LIBS $orig_LIBS"
    AC_LINK_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <resolv.h>]],
       [[unsigned char ans[256];
         int st = res_search("foo.bar", 1, 1, ans, sizeof(ans));]])],
       [ac_cv_lib_resolv_res_search=yes], [ac_cv_lib_resolv_res_search=no])
    LIBS=$orig_LIBS])
if test "$ac_cv_lib_resolv_res_search" = "yes"; then
   RESOLVER_LIBS=-lresolv
else
   RESOLVER_LIBS=
fi
NETWORK_LIBS="$RESOLVER_LIBS $NETWORK_LIBS"

orig_LIBS=$LIBS
LIBS="$NETWORK_LIBS $orig_LIBS"
AC_CHECK_FUNCS(inet_ntoa_r)
AC_CACHE_CHECK([for getaddrinfo], ac_cv_func_getaddrinfo,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <netdb.h>]],
       [[struct addrinfo *p; getaddrinfo("foo", "bar", p, &p);]])],
       [ac_cv_func_getaddrinfo=yes], [ac_cv_func_getaddrinfo=no])])
test "$ac_cv_func_getaddrinfo" = "yes" && \
  AC_DEFINE(HAVE_GETADDRINFO, 1,
            [Define to 1 if you have the `getaddrinfo' function.])
AC_CACHE_CHECK([for getnameinfo], ac_cv_func_getnameinfo,
   [AC_LINK_IFELSE([AC_LANG_PROGRAM(
       [[@%:@include <netdb.h>
         @%:@include <sys/types.h>
         @%:@include <sys/socket.h>]],
       [[struct sockaddr p; char buf[256], buf2[256];
         getnameinfo(&p, sizeof(p), buf, 256, buf2, 256, 0);]])],
       [ac_cv_func_getnameinfo=yes], [ac_cv_func_getnameinfo=no])])
test "$ac_cv_func_getnameinfo" = "yes" && \
  AC_DEFINE(HAVE_GETNAMEINFO, 1,
            [Define to 1 if you have the `getnameinfo' function.])
AC_CHECK_FUNCS(freehostent gethostent_r getipnodebyaddr getipnodebyname \
               inet_ntop socketpair)
LIBS=$orig_LIBS


### Save original compiler/linker flags
orig_CPPFLAGS="$CPPFLAGS"
orig_LDFLAGS="$LDFLAGS"
orig_LIBS="$LIBS"


### Check for math functions that aren't always available
AC_CHECK_FUNCS(erf)

NCBI_CHECK_LIBS(KSTAT, kstat, kstat_open)
NCBI_CHECK_LIBS(RPCSVC, rpcsvc, rstat)
AC_LANG_PUSH(C)
# Force C for this test because Sun WorkShop otherwise complains about
# multiple extern "C" declarations of setkey.
NCBI_CHECK_LIBS(CRYPT, crypt crypt_i, setkey)
AC_LANG_POP(C)
case "$host_os:$compiler" in
     linux*:ICC   ) ac_cv_search_dlopen="-ldl" ;;
     solaris*:GCC ) ac_cv_search_dlopen="-ldl" ;;
     darwin*      ) ac_cv_search_iconv="-liconv" ;;
esac
# Temporarily drop -fsanitize= flags for this test, as some toolchains count
# the support library's indirect use of libdt when building applications
# but not when building shared libraries with --no-undefined.
orig_CXXFLAGS=$CXXFLAGS
orig_LDFLAGS=$LDFLAGS
CXXFLAGS=`echo $CXXFLAGS | sed -e 's/[[^ ]]*fsanitize=[[^ ]]*//g'`
LDFLAGS=`echo $LDFLAGS | sed -e 's/[[^ ]]*fsanitize=[[^ ]]*//g'`
NCBI_CHECK_LIBS(DL, dl, dlopen)
CXXFLAGS=$orig_CXXFLAGS
LDFLAGS=$orig_LDFLAGS
orig_LIBS="$DL_LIBS $orig_LIBS"
# Left alone for the sake of anything using $(C_LIBS) in lieu of $(ORIG_LIBS).
# DL_LIBS=
dnl NCBI_CHECK_LIBS(UUID, uuid, uuid_generate)
AC_SEARCH_LIBS(uuid_generate, uuid,
   [NCBI_PACKAGE(UUID)
    test "x$ac_cv_search_uuid_generate" = "xnone required" || \
       UUID_LIBS=$ac_cv_search_uuid_generate])
LIBS=$orig_LIBS
dnl NCBI_CHECK_LIBS(FUSE, fuse, fuse_loop)
AC_SEARCH_LIBS(fuse_loop, fuse, [NCBI_PACKAGE(FUSE)])
LIBS=$orig_LIBS
# Temporarily drop OpenMP flags for this test, as some toolchains count
# its support library's indirect use of librt when building applications
# but not when building shared libraries with --no-undefined.
orig_CXXFLAGS=$CXXFLAGS
orig_LDFLAGS=$LDFLAGS
CXXFLAGS=`echo $CXXFLAGS | sed -e 's/[[^ ]]*openmp[[^ ]]*//g'`
LDFLAGS=`echo $LDFLAGS | sed -e 's/[[^ ]]*openmp[[^ ]]*//g'`
NCBI_CHECK_LIBS(RT, rt posix4, clock_gettime)
CXXFLAGS=$orig_CXXFLAGS
LDFLAGS=$orig_LDFLAGS
NCBI_CHECK_LIBS(DEMANGLE, demangle, cplus_demangle)
# Add to (orig_)LIBS if present for the sake of corelib and the
# following call to AC_CHECK_FUNCS.
if test -n "$DEMANGLE_LIBS$RT_LIBS"; then
    LIBS="$DEMANGLE_LIBS $RT_LIBS $LIBS"
    orig_LIBS="$DEMANGLE_LIBS $RT_LIBS $orig_LIBS"
fi
AC_CHECK_FUNCS([clock_gettime nanosleep pthread_cond_timedwait_relative_np \
                pthread_condattr_setclock sched_yield])
AC_CHECK_DECLS([CLOCK_MONOTONIC, CLOCK_SGI_CYCLE, CLOCK_REALTIME], [], [],
   [[@%:@include <time.h>
     @%:@ifdef HAVE_SYS_TIME_H
     @%:@  include <sys/time.h>
     @%:@endif]])

dnl NCBI_CHECK_LIBS(ICONV, iconv, iconv)
# We need to include <iconv.h>, since some implementations rename the symbols.
# This logic adapted from Bruno Haible's iconv.m4.
AC_CACHE_CHECK(for library containing iconv, ac_cv_search_iconv, [
   ac_cv_search_iconv=no
   AC_LINK_IFELSE(
      [AC_LANG_PROGRAM(
         [[@%:@include <stdlib.h>
           @%:@include <iconv.h>]],
         [[iconv_t cd = iconv_open("","");
           iconv(cd,NULL,NULL,NULL,NULL);
           iconv_close(cd);]])],
      [ac_cv_search_iconv="none required"])
   if test "$ac_cv_search_iconv" != "none required"; then
      for l in iconv; do
         LIBS="-l$l $orig_LIBS"
         AC_LINK_IFELSE(
            [AC_LANG_PROGRAM(
                [[@%:@include <stdlib.h>
                  @%:@include <iconv.h>]],
                [[iconv_t cd = iconv_open("","");
                  iconv(cd,NULL,NULL,NULL,NULL);
                  iconv_close(cd);]])],
            [ac_cv_search_iconv=-l$l])
         LIBS="$orig_LIBS"
      done
   fi])
if test "x$ac_cv_search_iconv" != xno; then
   NCBI_PACKAGE(Iconv)
   AC_DEFINE(HAVE_LIBICONV, 1,
   [Define to 1 if ICONV is available, either in its own library or as part
    of the standard libraries.])
   AC_MSG_CHECKING([for iconv declaration])
   AC_CACHE_VAL(am_cv_proto_iconv, [
      AC_COMPILE_IFELSE([
         AC_LANG_SOURCE([
@%:@include <stdlib.h>
@%:@include <iconv.h>
extern
@%:@ifdef __cplusplus
"C"
@%:@endif
@%:@if defined(__STDC__) || defined(__cplusplus)
size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
@%:@else
size_t iconv();
@%:@endif
])], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
      am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
   am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
   AC_MSG_RESULT([$]{ac_t:-
       }[$]am_cv_proto_iconv)
   AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
     [Define as const if the declaration of iconv() needs const.])
   if test "x$ac_cv_search_iconv" != "xnone required"; then
      ICONV_LIBS=$ac_cv_search_iconv
   fi
fi


### Third-party libraries

#### Set compiler prefix (empty for vendor compilers)
case "$signature_compiler:$ac_cv_have_decl__LIBCPP_VERSION" in
   Clang:no | LLVMGCC:no )
      compiler_pfx="GCC-"
      : ${gccver=`$CXX -dumpversion`}
      compiler_vpfx="GCC`echo $gccver | tr -d .`-"
      ;;
   Clang:* | *[[GIK]]CC:* )
      compiler_pfx="${signature_compiler}-"
      compiler_vpfx="${signature_compiler}${compiler_version}-"
      ;;
esac

usr_lib=['[/usr]*/lib/*[amdsprcv]*[23469]*']
no_usr_lib="s,-L$usr_lib ,,g; s,-L/usr/lib/$multiarch ,,g"

: ${with_libunwind:=no}
NCBI_CHECK_THIRD_PARTY_LIB_EX(libunwind, LIBUNWIND, unwind,
 [AC_LANG_PROGRAM([@%:@include <libunwind.h>
                   @%:@include <stdlib.h>],
      [[void *buffer; unw_backtrace(&buffer, 9);]])])
LIBS="$LIBUNWIND_LIBS $LIBS"
orig_LIBS="$LIBUNWIND_LIBS $orig_LIBS"

NCBI_CHECK_THIRD_PARTY_LIB_EX(libdw, LIBDW, dw,
 [AC_LANG_PROGRAM([@%:@include <elfutils/libdw.h>],
      [[Dwarf* d = dwarf_begin(17, DWARF_C_READ);]])])
LIBS="$LIBDW_LIBS $LIBS"
orig_LIBS="$LIBDW_LIBS $orig_LIBS"

NCBI_CHECK_THIRD_PARTY_LIB_EX(backward_cpp, BACKWARD_CPP, backward,
 [AC_LANG_PROGRAM([@%:@ifdef HAVE_LIBUNWIND
                   @%:@  define BACKWARD_HAS_UNWIND 1
                   @%:@else
                   @%:@  define BACKWARD_HAS_BACKTRACE 1
                   @%:@endif
                   @%:@ifdef HAVE_LIBDW
                   @%:@  define BACKWARD_HAS_DW 1
                   @%:@endif
                   @%:@include <backward.hpp>],
      [[backward::StackTrace st; st.load_here(32);]])],
 [], [], [$LIBUNWIND_INCLUDE $LIBDW_INCLUDE])


if test "$with_backward_cpp_sig" = yes; then
   AC_DEFINE(USE_LIBBACKWARD_SIG_HANDLING, 1,
             [Define to allow backward-cpp to also handle signals.])
fi

NCBI_CHECK_THIRD_PARTY_LIB(z,
 [AC_LANG_PROGRAM([@%:@include <zlib.h>],
      [[gzFile fp; char buf[1024]; int n = gzread(fp, buf, sizeof(buf))]])])
if test -z "$Z_LIBS"; then
   zlocal=util/compress/zlib
   AC_MSG_NOTICE([using local zlib copy in $zlocal])
   Z_PATH="<$zlocal>"
   Z_INCLUDE="-I\$(includedir)/$zlocal -I\$(includedir0)/$zlocal"
   # Z_LIBS="-lz"
   Z_LIB="z"
   # AC_DEFINE(USE_LOCAL_ZLIB, 1, [Define to 1 if using a local copy of zlib.])
   NCBI_PACKAGE(Z)
   NCBI_PACKAGE(LocalZ)
fi

NCBI_CHECK_THIRD_PARTY_LIB(bz2,
 [AC_LANG_PROGRAM([@%:@include <bzlib.h>],
      [[BZFILE* fp; char buf[1024]; int err;
        int n = BZ2_bzRead(&err, fp, buf, sizeof(buf))]])])
if test -z "$BZ2_LIBS"; then
   bzlocal=util/compress/bzip2
   AC_MSG_NOTICE([using local bzlib copy in $bzlocal])
   BZ2_PATH="<$bzlocal>"
   BZ2_INCLUDE="-I\$(includedir)/$bzlocal -I\$(includedir0)/$bzlocal"
   # BZ2_LIBS="-lbz2"
   BZ2_LIB="bz2"
   AC_DEFINE(USE_LOCAL_BZLIB, 1, [Define to 1 if using a local copy of bzlib.])
   NCBI_PACKAGE(BZ2)
   NCBI_PACKAGE(LocalBZ2)
fi

case "$with_lzo" in
   no       ) ;;
   yes | "" ) ;;
   *        ) LZO_PATH=$with_lzo ;;
esac
if test -d "$LZO_PATH"; then
   NCBI_FIX_DIR(LZO_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(lzo, LZO, lzo2,
 [AC_LANG_PROGRAM([@%:@include <lzo/lzo1x.h>],
      [[lzo_uint32 c = lzo_crc32(0, (const unsigned char*)"foo", 3);]])])
if test -n "$LZO_LIBS" -a "x$with_bin_release" = xyes \
        -a \( -f "$LZO_PATH/lib$bit64_sfx/liblzo2-static.a" \
              -o -f "$LZO_PATH/lib/liblzo2-static.a" \); then
   LZO_LIBS="$LZO_LIBPATH -llzo2-static"
fi

case "$with_zstd" in
   no       ) ;;
   yes | "" ) ;;
   *        ) ZSTD_PATH=$with_zstd ;;
esac
if test -d "$ZSTD_PATH"; then
   NCBI_FIND_ARCH_PATH(ZSTD)
   ZSTD_PATH=$ZSTD_ARCH_PATH
   NCBI_FIX_DIR(ZSTD_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(zstd,
 [AC_LANG_PROGRAM([@%:@define ZSTD_STATIC_LINKING_ONLY 1
                   @%:@include <zstd.h>],
      [[ZSTD_CCtx* cctx = ZSTD_createCCtx();
        return ZSTD_c_literalCompressionMode;]])])
if test -n "$ZSTD_LIBS" -a \( -f "$ZSTD_PATH/lib$bit64_sfx/libzstd-static.a" \
                              -o -f "$ZSTD_PATH/lib/libzstd-static.a" \); then
   ZSTD_STATIC_LIBS="$ZSTD_LIBPATH -lzstd-static"
else
   ZSTD_STATIC_LIBS=$ZSTD_LIBS
fi
if test "x$with_bin_release" = xyes; then
   ZSTD_LIBS=$ZSTD_STATIC_LIBS
fi

case "$with_pcre" in
   no       ) ;;
   yes | "" ) ;;
   *        ) PCRE_PATH=$with_pcre ;;
esac
if test -z "$PCRE_PATH"  &&  pcre-config --version >/dev/null 2>&1; then
    p=`pcre-config --prefix`
    test "x$p" = "x/usr"  ||  PCRE_PATH=$p
fi
NCBI_CHECK_THIRD_PARTY_LIB(pcre,
 [AC_LANG_PROGRAM([@%:@include <pcre.h>],
   [[const char*s[]={"x"}; pcre* p; pcre_extra* x = pcre_study(p, 1, s);]])])
if test -z "$PCRE_LIBS"; then
   pcrelocal=util/regexp
   AC_MSG_NOTICE([using local PCRE copy in $pcrelocal])
   PCRE_PATH="<$pcrelocal>"
   PCRE_INCLUDE="-I\$(includedir)/$pcrelocal -I\$(includedir0)/$pcrelocal"
   # PCRE_LIBS="-lregexp"
   # PCREPOSIX_LIBS="-lregexp"
   PCRE_LIB="regexp"
   AC_DEFINE(USE_LOCAL_PCRE, 1, [Define to 1 if using a local copy of PCRE.])
   NCBI_PACKAGE(PCRE)
   NCBI_PACKAGE(LocalPCRE)
else
   PCREPOSIX_LIBS=`echo "$PCRE_LIBS" | sed -e 's/-lpcre/-lpcreposix -lpcre/'`
fi

## SSL/TLS libraries (and supporting libraries)
if test "x${with_mbedtls-no}" != xno; then
   case "$with_mbedtls" in
      yes ) ;;
      *   ) MBEDTLS_PATH=$with_mbedtls ;;
   esac
   d="$MBEDTLS_PATH/${DEBUG_SFX}${mt_sfx}${bit64_sfx}"
   if test -d "$d"; then
      MBEDTLS_PATH=$d
   fi
   if test -d "$MBEDTLS_PATH"; then
      NCBI_FIX_DIR(MBEDTLS_PATH)
   fi
   NCBI_CHECK_THIRD_PARTY_LIB(mbedtls,
      [AC_LANG_PROGRAM([@%:@include <mbedtls/ssl.h>],
           [[mbedtls_ssl_context ssl; mbedtls_ssl_init(&ssl);]])],
      [[-lmbedx509 -lmbedcrypto $Z_LIBS]])
   if test -n "$MBEDTLS_LIBS" -a -f "$MBEDTLS_PATH/lib/libmbedtls-static.a" \
      -a "x$with_static_mbedtls" = xyes; then
      MBEDTLS_LIBS="-L$MBEDTLS_PATH/lib -lmbedtls-static -lmbedx509-static -lmbedcrypto-static $Z_LIBS"
   fi
fi
if test -z "$MBEDTLS_LIBS"; then
   mbedtls_local=connect/mbedtls
   AC_MSG_NOTICE([using local mbedTLS copy in $mbedtls_local])
   MBEDTLS_INCLUDE=""
   MBEDTLS_LIBS="$Z_LIBS"
   NCBI_PACKAGE(MBEDTLS)
fi

if test "x$with_gmp" != xno; then
   case "$with_gmp" in
      yes | '' ) ;;
      *        ) GMP_PATH=$with_gmp ;;
   esac
   for pfx in "$compiler_vpfx" "$compiler_pfx" "" ; do
      vpath=$GMP_PATH/$pfx${DEBUG_SFX}${mt_sfx}${bit64_sfx}
      if test -d "$vpath" ; then
         GMP_PATH=$vpath
         break
      fi
   done
   if test -d "$GMP_PATH"; then
      NCBI_FIX_DIR(GMP_PATH)
   fi
   NCBI_CHECK_THIRD_PARTY_LIB(gmp,
      [AC_LANG_PROGRAM([@%:@include <gmp.h>],
           [[mpz_t x; mpz_init(x);]])])
fi
if test "$with_gmp" = no; then
   AS_UNSET(GMP_INCLUDE)
   AS_UNSET(GMP_LIBS)
else
   NCBI_PACKAGE(GMP)
fi

case "$with_gcrypt" in
   no )       ac_cv_path_LIBGCRYPT_CONFIG=no ;;
   yes | '' )                                ;;
   * )        GCRYPT_PATH=$with_gcrypt       ;;
esac
if test -d "$GCRYPT_PATH"; then
   NCBI_FIX_DIR(GCRYPT_PATH)
fi
AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, [], [${GCRYPT_BIN-$GCRYPT_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}/bin}:$GCRYPT_PATH/bin${bit64_sfx}:$GCRYPT_PATH/bin:$PATH])

if test "x$with_gcrypt" != xno; then
   if test -x "$LIBGCRYPT_CONFIG"; then
      if test -z "$GCRYPT_PATH"; then
         p=`libgcrypt-config --prefix`
         test "x$p" = "x/usr"  ||  GCRYPT_PATH=$p
      fi
      NCBI_RPATHIFY_OUTPUT(GCRYPT_LIBPATH,
        [$LIBGCRYPT_CONFIG --exec-prefix], [s,^,-L,; s,$,/lib,;])
      GCRYPT_INCLUDE=`$LIBGCRYPT_CONFIG --cflags`
      GCRYPT_CONFIG_LIBS="`$LIBGCRYPT_CONFIG --libs` $Z_LIBS"
   fi
else
   AS_UNSET(GCRYPT_CONFIG_LIBS)
fi
NCBI_CHECK_THIRD_PARTY_LIB(gcrypt,
 [AC_LANG_PROGRAM([[@%:@include <gcrypt.h>
                     @%:@include <pthread.h>
                     @%:@include <errno.h>
                     GCRY_THREAD_OPTION_PTHREAD_IMPL;]],
   [[gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);]])],
 $GCRYPT_CONFIG_LIBS)
if test "x$with_gcrypt" != xno -a -n "$GCRYPT_CONFIG_LIBS"; then
   NCBI_RPATHIFY_OUTPUT(GCRYPT_LIBS, [echo $GCRYPT_CONFIG_LIBS], [$no_usr_lib])
fi

if test "x$with_nettle" != xno; then
   case "$with_nettle" in
      yes | '' ) ;;
      *        ) NETTLE_PATH=$with_nettle ;;
   esac
   if test -d "$NETTLE_PATH"; then
      NCBI_FIX_DIR(NETTLE_PATH)
   fi
   if test -d "$NETTLE_PATH/lib$bit64_sfx"; then
      NETTLE_LIBDIR=$NETTLE_PATH/lib$bit64_sfx
   else
      NETTLE_LIBDIR=$NETTLE_PATH/lib
   fi
   for pfx in "$compiler_vpfx" "$compiler_pfx" "" ; do
      vpath=$NETTLE_PATH/$pfx${DEBUG_SFX}${mt_sfx}${bit64_sfx}
      if test -d "$vpath" ; then
         NETTLE_LIBDIR=$vpath/lib
         break
      fi
   done
   if test -d "$NETTLE_LIBDIR"; then
      NCBI_FIX_DIR(NETTLE_LIBDIR)
      NCBI_RPATHIFY(NETTLE_LIBPATH, $NETTLE_LIBDIR)
   fi
   NCBI_CHECK_THIRD_PARTY_LIB_EX(nettle, NETTLE, hogweed,
      [AC_LANG_PROGRAM([@%:@include <nettle/sexp.h>],
           [[struct sexp_iterator it;
             sexp_iterator_first(&it, 0, (const uint8_t*) NULL);]])],
      [-lnettle], [$GMP_LIBS])
fi
if test "$with_nettle" = no; then
   AS_UNSET(NETTLE_INCLUDE)
   AS_UNSET(NETTLE_LIBS)
else
   NCBI_PACKAGE(NETTLE)
fi

case "${with_gnutls=no}" in
   no  ) ac_cv_path_LIBGNUTLS_CONFIG=no ;;
   yes )                                ;;
   *   ) GNUTLS_PATH=$with_gnutls       ;;
esac
if test -d "$GNUTLS_PATH"; then
   NCBI_FIX_DIR(GNUTLS_PATH)
   gnutls_config_path=${GNUTLS_BIN-$GNUTLS_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}/bin}:$GNUTLS_PATH/bin${bit64_sfx}:$GNUTLS_PATH/bin
else
   gnutls_config_path=$PATH
fi
AC_PATH_PROG(LIBGNUTLS_CONFIG, libgnutls-config, [], [$gnutls_config_path])

if test "x$with_gnutls" != xno; then
   if test -x "$LIBGNUTLS_CONFIG"; then
      if test -z "$GNUTLS_PATH"; then
         p=`$LIBGNUTLS_CONFIG --prefix`
         test "x$p" = "x/usr"  ||  GNUTLS_PATH=$p
      fi
   else
      LIBGNUTLS_CONFIG="eval PKG_CONFIG_PATH=\"$GNUTLS_PATH/lib$bit64_sfx/pkgconfig:$GNUTLS_PATH/lib/pkgconfig\" pkg-config gnutls --static"
      $LIBGNUTLS_CONFIG --exists >/dev/null 2>&1 ||  LIBGNUTLS_CONFIG=no
   fi
   case "$LIBGNUTLS_CONFIG" in
       eval\ *)
           NCBI_RPATHIFY_OUTPUT(GNUTLS_LIBPATH,
             [$LIBGNUTLS_CONFIG --libs-only-L])
           GNUTLS_CONFIG_LIBS=`$LIBGNUTLS_CONFIG --libs-only-l`
           GNUTLS_CONFIG_LIBS="$GNUTLS_LIBPATH $GNUTLS_CONFIG_LIBS $Z_LIBS"
           ;;
       no)
           ;;
       *)
           NCBI_RPATHIFY_OUTPUT(GNUTLS_LIBPATH,
             [$LIBGNUTLS_CONFIG --exec-prefix], [s,^,-L,; s,$,/lib,;])
           GNUTLS_CONFIG_LIBS="`$LIBGNUTLS_CONFIG --libs` $Z_LIBS"
           ;;
   esac

   if test "x$LIBGNUTLS_CONFIG" != xno; then
      GNUTLS_INCLUDE=`$LIBGNUTLS_CONFIG --cflags`
   fi
else
   AS_UNSET(GNUTLS_CONFIG_LIBS)
fi
NCBI_CHECK_THIRD_PARTY_LIB(gnutls,
 [AC_LANG_PROGRAM([[@%:@include <gnutls/gnutls.h>]],
   [[gnutls_session_t s; gnutls_init(&s, GNUTLS_CLIENT);]])],
 [$GNUTLS_CONFIG_LIBS], [$GCRYPT_LIBS $NETTLE_LIBS $GMP_LIBS])
if test "x$with_gnutls" != xno; then
   AC_CHECK_FUNCS([gnutls_certificate_set_verify_function \
                   gnutls_record_disable_padding gnutls_rnd])
   AC_CHECK_HEADERS([gnutls/abstract.h])
   if test -n "$GNUTLS_CONFIG_LIBS"; then
      NCBI_RPATHIFY_OUTPUT(GNUTLS_LIBS, [echo $GNUTLS_CONFIG_LIBS],
         [$no_usr_lib])
   else
      GNUTLS_LIBS="$GNUTLS_LIBS $NETTLE_LIBS $GMP_LIBS"
   fi
   # Conservatively build against gcrypt if available even when gnutls
   # uses nettle instead, because gcrypt needs explicit initialization
   # to be thread-safe, but gnutls's headers don't indicate which
   # underlying crypto library it's actually using.
   case "$GNUTLS_INCLUDE" in
       *$GCRYPT_INCLUDE* ) ;;
       *                 ) GNUTLS_INCLUDE="$GNUTLS_INCLUDE $GCRYPT_INCLUDE" ;;
   esac
   case "$GNUTLS_LIBS" in
       *\ -lgcrypt* ) ;;
       *            ) GNUTLS_LIBS="$GNUTLS_LIBS $GCRYPT_LIBS" ;;
   esac
   if test "$with_static_gnutls" = yes; then
      dirs=''
      sep=''
      static_libs=''
      for x in $GNUTLS_LIBS; do
         case $x in
            -L* ) dirs="$dirs `echo _$x | cut -c4-`" ;;
            -l* )
                want=lib`echo _$x | cut -c4-`-static.a
                for d in $dirs; do
                   if test -f $d/$want; then
                      x=$x-static
                      break
                   fi
                done
                ;;
         esac
         static_libs=$static_libs$sep$x
         sep=' '
      done
      GNUTLS_LIBS="$static_libs $ICONV_LIBS"
   fi
fi

NCBI_CHECK_THIRD_PARTY_LIB_EX(openssl, OPENSSL, ssl,
 [AC_LANG_PROGRAM([[@%:@include <openssl/ssl.h>]],
   [[SSL_library_init();]])],
 -lcrypto)

OPENSSL_STATIC_LIBS=$OPENSSL_LIBS
for d in `echo " $OPENSSL_LIBS" | fmt -w 1 | sed -ne 's/^ *-L//p'` \
   /usr/local/lib${bit64_sfx} /usr/local/lib /usr/lib${bit64_sfx} /usr/lib; do
   if test -f $d/libssl.a -a -f $d/libcrypto.a; then
      OPENSSL_STATIC_LIBS="$d/libssl.a $d/libcrypto.a"
      break
   elif test -f $d/libssl.so -o -f $d/libssl.dylib; then
      break
   fi
done

NETWORK_LIBS="$GNUTLS_LIBS $MBEDTLS_LIBS $NETWORK_LIBS"

case "$with_krb5" in
   no )       ac_cv_path_KRB5_CONFIG=no    ;;
   yes | '' ) : ${KRB5_PATH=/usr/kerberos} ;;
   * )        KRB5_PATH=$with_krb5         ;;
esac
AC_PATH_PROG(KRB5_CONFIG, krb5-config, [], [${KRB5_BIN-$KRB5_PATH/bin}:$PATH])

if test "x$with_krb5" != xno; then
   if test -x "$KRB5_CONFIG"; then
      KRB5_PATH=`$KRB5_CONFIG --prefix`
      KRB5_INCLUDE=`$KRB5_CONFIG --cflags | \
         sed -e 's/$/ /; s,-I/usr/include ,,'`
      KRB5_CONFIG_LIBS=`$KRB5_CONFIG --libs gssapi | \
         sed -e 's/^/ /; s/ -[[^Ll]][[^ ]]*//g'`
   fi
else
   dnl AS_UNSET(KRB5_CONFIG_LIBS)
   KRB5_CONFIG_LIBS=$KRB5_LIBS
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(krb5, KRB5, gssapi_krb5,
 [AC_LANG_PROGRAM([[@%:@include <time.h>
@%:@ifdef HAVE_INTTYPES_H
@%:@  include <inttypes.h>
@%:@endif
extern "C" {
@%:@include <gssapi/gssapi_krb5.h>
}]],
   [[OM_uint32 min_stat;
     gss_buffer_desc buf;
     gss_release_buffer(&min_stat, &buf);]])],
 $KRB5_CONFIG_LIBS)
if test "x$with_krb5" != xno; then
   AC_CHECK_FUNCS([error_message])
   AC_CHECK_HEADERS([com_err.h roken.h])
   NCBI_RPATHIFY_OUTPUT(KRB5_LIBS, [echo $KRB5_CONFIG_LIBS], [$no_usr_lib])
fi


case "$with_curl" in
   no       ) ac_cv_path_CURL_CONFIG=no ;;
   yes | "" )                           ;;
   *        ) CURL_PATH=$with_curl      ;;
esac
if test -d "$CURL_PATH"; then
   NCBI_FIX_DIR(CURL_PATH)
   NCBI_FIND_ARCH_PATH(CURL)
   NCBI_FIX_DIR(CURL_ARCH_PATH)
fi
AC_PATH_PROG(CURL_CONFIG, curl-config, [], [$CURL_ARCH_PATH/bin:$PATH])
if test -x "$CURL_CONFIG"; then
   : ${CURL_INCLUDE=`"$CURL_CONFIG" --cflags`}
   NCBI_RPATHIFY_OUTPUT_COND(CURL_LIBPATH, ["$CURL_CONFIG" --libs],
      [s/ -lcurl[[^ ]]*//; ])
   CURL_PATH=`"$CURL_CONFIG" --prefix`
elif test -d "$CURL_ARCH_PATH"; then
   : ${CURL_INCLUDE=-I$CURL_PATH/include}
   NCBI_RPATHIFY_COND(CURL_LIBPATH, $CURL_ARCH_PATH/lib)
fi
NCBI_CHECK_THIRD_PARTY_LIB(curl,
   [AC_LANG_PROGRAM([@%:@include <curl/curl.h>],
       [char* v = curl_version();])])
if test -n "$CURL_LIBS"; then
   if test -x "$CURL_CONFIG"; then
      CURL_STATIC_LIBS=`"$CURL_CONFIG" --static-libs`
   elif test -f "$CURL_ARCH_PATH/lib/libcurl-static.a"; then
      # Speculative
      CURL_STATIC_LIBS="$CURL_LIBPATH -lcurl-static $OPENSSL_LIBS $Z_LIBS"
   fi
   : ${CURL_STATIC_LIBS:=$CURL_LIBS}
fi


## SYBASE libraries

NETWORK_PURE_LIBS="$NETWORK_LIBS"
if test "$with_sybase" != "no" ; then
   resolve_sybase=true
   default_pointer=default-${NCBI_PLATFORM_BITS}bit
   : ${with_sybase_new:="no"}
   case "$host_os" in
      linux* )
         : ${with_sybase_local:=yes}
         ;;
      * )
         if test -d "$net_sybase_root" ; then
            : ${with_sybase_local:=no}
         else
            : ${with_sybase_local:=yes}
         fi
         ;;
   esac

   if test "$with_sybase_local" != "no" ; then
      if test "$with_sybase_local" = "yes" ; then
         if test -n "$SYBASE_PATH" ; then
            with_sybase_local=$SYBASE_PATH
         else
            if test "$with_sybase_new" = "yes" ; then
               with_sybase_local=$local_sybase_root/new
            elif test -f "$local_sybase_root/$default_pointer" ; then
               with_sybase_local=`cat $local_sybase_root/$default_pointer`
               resolve_sybase=false
            else
               with_sybase_local=$local_sybase_root/current
            fi
            if test -d "$with_sybase_local$NCBI_PLATFORM_BITS" ; then
               with_sybase_local=$with_sybase_local$NCBI_PLATFORM_BITS
            fi
         fi # default paths
      fi # no command-line path
      if test -d "$with_sybase_local" ; then
         SYBASE_PATH=$with_sybase_local
         SYBASE_LCL_PATH=
      else
         with_sybase_local=no
      fi
   fi

   if test "$with_sybase_local" = "no" ; then
      if test "$with_sybase_new" = "yes" ; then
         if test -d "$net_sybase_root/new$NCBI_PLATFORM_BITS" ; then
            SYBASE_LCL_PATH=$local_sybase_root/new$NCBI_PLATFORM_BITS
            SYBASE_PATH=$net_sybase_root/new$NCBI_PLATFORM_BITS
         elif test -d "$net_sybase_root/new" ; then
            SYBASE_LCL_PATH=$local_sybase_root/new
            SYBASE_PATH=$net_sybase_root/new
         else
            with_sybase_new=no
         fi
      fi

      if test -z "$SYBASE_PATH" ; then
         if test -f "$net_sybase_root/$default_pointer" ; then
            SYBASE_LCL_PATH=
            SYBASE_PATH=`cat $local_sybase_root/$default_pointer`
            resolve_sybase=false
         elif test -d "$net_sybase_root/current$NCBI_PLATFORM_BITS" ; then
            SYBASE_LCL_PATH=$local_sybase_root/current$NCBI_PLATFORM_BITS
            SYBASE_PATH=$net_sybase_root/current$NCBI_PLATFORM_BITS
         elif test -d "$net_sybase_root/current" ; then
            SYBASE_LCL_PATH=$local_sybase_root/current
            SYBASE_PATH=$net_sybase_root/current
         else
            SYBASE_LCL_PATH=
            SYBASE_PATH=$SYBASE
         fi
      fi
   fi

   # Lock in the version we found, ignoring symlinks further up
   case "$SYBASE_PATH" in
      */[[1-9]]* ) resolve_sybase=false ;;
   esac
   if test -d "$SYBASE_PATH"  &&  $resolve_sybase; then
      # SYBASE_PATH_=`cd $SYBASE_PATH && /bin/pwd`
      SYBASE_PATH_=`ls -ld $SYBASE_PATH | sed -ne 's/.* -> //p'`
      case "$SYBASE_PATH_" in
         '' ) ;;
         /* )
            SYBASE_VERSION=`basename $SYBASE_PATH_`
            SYBASE_PATH=`dirname $SYBASE_PATH`/$SYBASE_VERSION
            test -d "$SYBASE_PATH"  ||  SYBASE_PATH=$SYBASE_PATH_
            ;;
         * )
            orig_parent=`dirname $SYBASE_PATH`
            SYBASE_VERSION=`basename $SYBASE_PATH_`
            SYBASE_PATH=$orig_parent/$SYBASE_VERSION
            test -d "$SYBASE_PATH"  ||  SYBASE_PATH=$orig_parent/$SYBASE_PATH_
            ;;
      esac
   fi

   if test -d "$SYBASE_LCL_PATH"  &&  $resolve_sybase ; then
      # SYBASE_LCL_PATH_=`cd $SYBASE_LCL_PATH && /bin/pwd`
      SYBASE_LCL_PATH_=`ls -ld $SYBASE_LCL_PATH | sed -ne 's/.* -> //p'`
      case "$SYBASE_LCL_PATH_" in
         '' ) ;;
         /* )
            SYBASE_LCL_VERSION=`basename $SYBASE_LCL_PATH_`
            SYBASE_LCL_PATH=`dirname $SYBASE_LCL_PATH`/$SYBASE_LCL_VERSION
            test -d "$SYBASE_LCL_PATH"  ||  SYBASE_LCL_PATH=$SYBASE_LCL_PATH_
            ;;
         * )
            orig_parent=`dirname $SYBASE_LCL_PATH`
            SYBASE_LCL_VERSION=`basename $SYBASE_LCL_PATH_`
            SYBASE_LCL_PATH=$orig_parent/$SYBASE_LCL_VERSION
            test -d "$SYBASE_LCL_PATH"  || \
               SYBASE_LCL_PATH=$orig_parent/$SYBASE_LCL_PATH_
            ;;
      esac
   elif test -n "$SYBASE_LCL_PATH" ; then
      SYBASE_LCL_PATH=`dirname $SYBASE_LCL_PATH`/$SYBASE_VERSION
   fi

   if test -n "$SYBASE_VERSION" -a -n "$SYBASE_LCL_VERSION" \
        -a "$SYBASE_VERSION" != "$SYBASE_LCL_VERSION" ; then
      AC_MSG_WARN([ignoring inconsistent local Sybase symlink: $SYBASE_LCL_VERSION vs. $SYBASE_VERSION])
      SYBASE_LCL_PATH=`dirname $SYBASE_LCL_PATH`/$SYBASE_VERSION
   fi

   if test -n "$SYBASE" ; then
      if test -d "$net_sybase_root" -o -d "$local_sybase_root" ; then
         case $SYBASE in
            $net_sybase_root/* | $local_sybase_root/* ) ;;
            * ) AC_MSG_WARN([ignoring non-standard SYBASE setting: $SYBASE]) ;;
            # Ignored regardless, but standard values are not so concerning.
         esac
      fi
   fi

   if test -f "$SYBASE_PATH/SYBASE.env"; then
      ocs=`sed -ne 's:^SYBASE_OCS=:/:p' "$SYBASE_PATH/SYBASE.env"`
   else
      ocs=
   fi
   if test -d "$SYBASE_PATH$ocslib$bit64_sfx"; then
      SYBASE_LIBPATH="$SYBASE_PATH$ocs/lib$bit64_sfx"
   else
      SYBASE_LIBPATH="$SYBASE_PATH$ocs/lib"
   fi
   syb_sfx=$bit64_sfx
   if test -f "$SYBASE_LIBPATH/libsybct$syb_sfx.a"; then
      syb_pfx=syb
   else
      syb_pfx=
   fi

   if test "$with_mt" = "yes" ; then
      AC_CACHE_CHECK([for reentrant Sybase libraries], ncbi_cv_lib_sybase_r,
         [if test -f "$SYBASE_LIBPATH/lib${syb_pfx}ct_r$bit64_sfx.so"; then
             ncbi_cv_lib_sybase_r=yes
          else
             ncbi_cv_lib_sybase_r=no
          fi])
      if test $ncbi_cv_lib_sybase_r = yes; then
         syb_sfx=_r$bit64_sfx
      fi
   fi
   case "$host_os" in
      linux*) sybtcl=-lsybtcl$syb_sfx; sybtli="" ;;
      *)      sybtcl=-l${syb_pfx}tcl$syb_sfx; sybtli=-ltli$syb_sfx ;;
   esac
   test -f "$SYBASE_LIBPATH/libtli.so" || sybtli=

   # quick-patch for the bad "tli" lib (Solaris8/Intel specific)
   case "$host_os:$host_vendor" in
      solaris*:pc )  : ${sybase_sol8pc_patch:="yes"} ;;
   esac
   if test "$sybase_sol8pc_patch" = "yes" ; then
      sybtli="-ltli_orig$syb_sfx -ltli$syb_sfx"
      SYBASE_NETWORK_LIBS="-ltli$syb_sfx $NETWORK_LIBS"
   else
      SYBASE_NETWORK_LIBS="$NETWORK_LIBS"
   fi

   if test -f "$SYBASE_LIBPATH/libsybunic${bit64_sfx}.a"; then
      sybunic=-lsybunic${bit64_sfx}
   fi

   test -n "$bit64_sfx"  &&  SYBASE_INCLUDE="-DSYB_LP64"
   SYBASE_LIBLIST="-l${syb_pfx}blk$syb_sfx -l${syb_pfx}ct$syb_sfx"
   SYBASE_LIBLIST="$SYBASE_LIBLIST -l${syb_pfx}cs$syb_sfx $sybtcl"
   SYBASE_LIBLIST="$SYBASE_LIBLIST -l${syb_pfx}comn$syb_sfx"
   SYBASE_LIBLIST="$SYBASE_LIBLIST -l${syb_pfx}intl$syb_sfx $sybunic"
   SYBASE_DLLLIST="$sybtli"

   # deduce conf.macro: SYBASE_INCLUDE, SYBASE_LIBS, SYBASE_DLLS, SYBASE_DBLIBS
   SYBASE_INCLUDE="-I$SYBASE_PATH$ocs/include $SYBASE_INCLUDE"
   if test -z "$SYBASE_LCL_PATH" ; then
      NCBI_RPATHIFY(SYBASE_LPATH, $SYBASE_LIBPATH)
   else
      SYBASE_LCL_LIBPATH="$SYBASE_LCL_PATH$ocs/${sybase_lib}"
      NCBI_RPATHIFY(SYBASE_LPATH, $SYBASE_LCL_LIBPATH $SYBASE_LIBPATH)
      SYBASE_INCLUDE="-I$SYBASE_LCL_PATH$ocs/include $SYBASE_INCLUDE"
   fi
   SYBASE_LIBS="$SYBASE_LPATH $SYBASE_LIBLIST"
   SYBASE_DBLIBS="$SYBASE_LPATH $SYBASE_DBLIBS"
   SYBASE_DLLS="$SYBASE_DLLLIST"

   AC_CACHE_CHECK([for Sybase${SYBASE_PATH:+ in $SYBASE_PATH}],
      ncbi_cv_lib_sybase,
      [CPPFLAGS="$SYBASE_INCLUDE $orig_CPPFLAGS"
       LIBS="$SYBASE_LIBS $SYBASE_DLLS $SYBASE_NETWORK_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <ctpublic.h>]],
          [[CS_RETCODE i = ct_init(0,0);  i = cs_ctx_global(0,0); ]])],
          [ncbi_cv_lib_sybase=yes], [ncbi_cv_lib_sybase=no])])

   if test "$ncbi_cv_lib_sybase" = yes; then
      NCBI_PACKAGE(Sybase)
      AC_DEFINE(HAVE_LIBSYBASE, 1,
                [Define to 1 if SYBASE libraries are available.])
      if test "$with_mt" = "yes" -a "$ncbi_cv_lib_sybase_r" = "yes"; then
         AC_DEFINE(HAVE_SYBASE_REENTRANT, 1,
                   [Define to 1 if SYBASE has reentrant libraries.])
      fi

      SYBASE_DBLIBS="$SYBASE_LPATH -lsybdb${bit64_sfx} $sybunic"
      AC_CACHE_CHECK([for Sybase DBLib], ncbi_cv_lib_sybdb,
         [CPPFLAGS="$SYBASE_INCLUDE $orig_CPPFLAGS"
          LIBS="$SYBASE_DBLIBS $SYBASE_LIBS $SYBASE_DLLS $SYBASE_NETWORK_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
             [[
              @%:@include <sybfront.h>
              @%:@include <sybdb.h>
             ]],
             [[
              LOGINREC*  x_login     = 0;
              DBPROCESS* x_dbproc    = dbopen(x_login, (char*) "SRV_NAME");
             ]])],
             [ncbi_cv_lib_sybdb=yes], [ncbi_cv_lib_sybdb=no])])
      if test "$ncbi_cv_lib_sybdb" = yes; then
         NCBI_PACKAGE(DBLib)
         AC_DEFINE(HAVE_LIBSYBDB, 1,
                   [Define to 1 if SYBASE DBLib is available.])
      else
         SYBASE_DBLIBS=
      fi
      # apply the Sybase patch to $NETWORK_LIBS
      if test "$sybase_sol8pc_patch" = "yes" ; then
         NETWORK_LIBS="$SYBASE_LPATH $SYBASE_NETWORK_LIBS"
      fi
   else
      NCBI_MISSING_PACKAGE(sybase)
   fi
fi # with_sybase != no?

if test "$with_sybase" = no; then
   SYBASE_PATH="No_Sybase"
   SYBASE_INCLUDE=
   SYBASE_LIBS=
   SYBASE_DLLS=
   SYBASE_DBLIBS=
fi

SYBASE_LPATH=
SYBASE_LCL_LIBPATH=
SYBASE_LIBLIST=
SYBASE_DLLLIST=
SYBASE_LIBPATH=


## FreeTDS libraries
freetds=
if test "$with_ftds" != "no" ; then
   ftds_ver=100
   try_local=yes
   case "$with_ftds" in
      100 | 1.00 | yes | '' )
         ;;
      * )
         FTDS_PATH=$with_ftds
         try_local=no
         ;;
   esac
   : ${FTDS_CTLIBS:="-lct -ltds $NETWORK_LIBS"}
   NCBI_RPATHIFY(FTDS_CTLIBS,   $FTDS_PATH/lib,      [ ]$FTDS_CTLIBS)
   FTDS_INCLUDE="-I$FTDS_PATH/include"
   NCBI_LOCAL_FTDS(100)
   if test -n "$freetds" ; then
      FTDS_LIB="\$(FTDS${ftds_ver}_LIB)"
      FTDS_LIBS="\$(FTDS${ftds_ver}_LIBS)"
      FTDS_INCLUDE="\$(FTDS${ftds_ver}_INCLUDE)"
      if test "$with_ftds_renamed" != "no" ; then
          AC_DEFINE(NCBI_FTDS_RENAME_SYBDB, 1,
                    [Rename DBLIB symbols in FTDS to avoid name clash with Sybase DBLIB.])
      fi
      AC_MSG_NOTICE([Using bundled FreeTDS (version $ftds_ver) from $FTDS_PATH])
   else
      FTDS_LIBS="$FTDS_CTLIBS"
      AC_CACHE_CHECK([for FreeTDS${FTDS_PATH:+ in $FTDS_PATH}],
         ncbi_cv_lib_freetds,
         [CPPFLAGS="$FTDS_INCLUDE $orig_CPPFLAGS"
          LIBS="$FTDS_LIBS $NETWORK_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
            [[
             @%:@include <sybdb.h>
             @%:@include <tds.h>
            ]],
            [[
             LOGINREC*  x_login     = 0;
             DBPROCESS* x_dbproc    = dbopen(x_login, (char*) "SRV_NAME");
             TDSLOGIN*  x_tds_login = 0;
             /* TDSSOCKET* x_sock      = tds_connect(x_tds_login); */
             tds_set_timeouts(x_tds_login, 0, 0, 0);
            ]])],
            [ncbi_cv_lib_freetds=yes], [ncbi_cv_lib_freetds=no])])
      if test "$ncbi_cv_lib_freetds" = "no"; then
         # Don't panic when using partial trees lacking dbapi/driver/ftdsN.
         NCBI_MISSING_PACKAGE(ftds)
      fi
   fi
fi
if test "$with_ftds" = "no" ; then
   FTDS_PATH=
   FTDS_INCLUDE=
   FTDS_LIBS=
   FTDS_LIB=
   FTDS100_INCLUDE=
   FTDS100_LIBS=
   FTDS100_LIB=
   FTDS100_CTLIB_INCLUDE=
   FTDS100_CTLIB_LIBS=
   FTDS100_CTLIB_LIB=
   freetds=
else
   AC_DEFINE(HAVE_LIBFTDS, 1,
             [Define to 1 if FreeTDS libraries are available.])
   NCBI_PACKAGE(FreeTDS)
fi
AC_SUBST(FTDS100_INCLUDE)
AC_SUBST(FTDS100_LIBS)
AC_SUBST(FTDS100_LIB)
AC_SUBST(FTDS100_CTLIB_INCLUDE)
AC_SUBST(FTDS100_CTLIB_LIBS)
AC_SUBST(FTDS100_CTLIB_LIB)
AC_SUBST(FTDS_INCLUDE)
AC_SUBST(FTDS_LIBS)
AC_SUBST(FTDS_LIB)
AC_SUBST(freetds)


## MySQL
if test "$with_mysql" != "no" ; then
   case "$with_mysql" in
      yes | "" ) ;;
      *        ) MYSQL_PATH=$with_mysql ;;
   esac
   : ${MYSQL_BINPATH=$MYSQL_PATH/bin}
   AC_PATH_PROG(mysql_config, mysql_config, [], [$MYSQL_BINPATH:$PATH])
   if test -n "$mysql_config" ; then
      : ${MYSQL_BINPATH=`dirname $mysql_config`}
      # Kill off single quotes, due to later requoting
      : ${MYSQL_INCLUDE=`$mysql_config --include | tr -d \'`}
      NCBI_RPATHIFY_OUTPUT_COND(MYSQL_LIBS, $mysql_config --libs${mt_sfx:+_r},
         [s/'//g; $no_usr_lib])
      AC_CACHE_CHECK([whether MySQL works], ncbi_cv_lib_mysql,
         [CPPFLAGS="$MYSQL_INCLUDE $orig_CPPFLAGS"
          LIBS="$MYSQL_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <mysql.h>]],
          [[MYSQL *p;  p = mysql_init(p);]])],
          [ncbi_cv_lib_mysql=yes], [ncbi_cv_lib_mysql=no])])
      if test "$ncbi_cv_lib_mysql" = no; then
         NCBI_MISSING_PACKAGE(mysql)
      fi
   else
      NCBI_MISSING_PACKAGE(mysql)
   fi
fi
if test "$with_mysql" = "no" ; then
   MYSQL_PATH="No_MYSQL"
   MYSQL_INCLUDE=
   MYSQL_LIBS=
else
   NCBI_PACKAGE(MySQL)
   AC_DEFINE(HAVE_MYSQL, 1, [Define to 1 if MySQL is available.])
fi


## Berkeley DB library
if test "$with_bdb" != "no" ; then
   case "$with_bdb" in
      yes | "" )
         ;;
      */*)
          BERKELEYDB_PATH=$with_bdb
          AS_UNSET(BERKELEYDB_INCLUDE)
          AS_UNSET(BERKELEYDB_LIBPATH)
          AS_UNSET(BERKELEYDB_LIBS)
          ;;
      *)
          BERKELEYDB_PATH=$NCBI/BerkeleyDB-${with_bdb}
          AS_UNSET(BERKELEYDB_INCLUDE)
          AS_UNSET(BERKELEYDB_LIBPATH)
          AS_UNSET(BERKELEYDB_LIBS)
          ;;
   esac
   if test -d "$BERKELEYDB_PATH"; then
      NCBI_FIX_DIR(BERKELEYDB_PATH)
      : ${BERKELEYDB_INCLUDE:="-I$BERKELEYDB_PATH/include"}
   fi
   if test -z "${BERKELEYDB_LIBPATH}"; then
      for d in "${compiler_vpfx}${DEBUG_SFX}" "${compiler_pfx}${DEBUG_SFX}" \
               "${DEBUG_SFX}" lib; do
         for sfx in "$mt_sfx$bit64_sfx" "$bit64_sfx$mt_sfx" "$bit64_sfx" \
                    "$mt_sfx" ""; do
            BERKELEYDB_LIBPATH=${BERKELEYDB_PATH}/$d$sfx
            test -d "${BERKELEYDB_LIBPATH}"  &&  break
         done
         test -d "${BERKELEYDB_LIBPATH}"  &&  break
      done
   fi
   if test -d "$BERKELEYDB_LIBPATH"; then
      NCBI_FIX_DIR(BERKELEYDB_LIBPATH)
      NCBI_RPATHIFY_COND(BERKELEYDB_LIBS:, ${BERKELEYDB_LIBPATH}, [ -ldb])
   else
      : ${BERKELEYDB_LIBS:="-ldb"}
   fi
   if test -f "${BERKELEYDB_LIBPATH}/libdb-static.a"; then
      BERKELEYDB_STATIC_LIBS="-L${BERKELEYDB_LIBPATH} -ldb-static"
      if test "x$with_bin_release" = "xyes"; then
         BERKELEYDB_LIBS=$BERKELEYDB_STATIC_LIBS
      fi
   else
      BERKELEYDB_STATIC_LIBS=${BERKELEYDB_LIBS}
   fi
   AC_CACHE_CHECK(
      [for Berkeley DB libraries${BERKELEYDB_PATH:+ in $BERKELEYDB_PATH}],
      ncbi_cv_lib_berkeley_db,
      [CPPFLAGS="$BERKELEYDB_INCLUDE $orig_CPPFLAGS"
       LIBS="$BERKELEYDB_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <db.h>
            @%:@include <stdlib.h>]],
          [[ DB* dbp;  db_create(&dbp, NULL, 0);  dbp->app_private = 0; ]])],
          [ncbi_cv_lib_berkeley_db=yes], [ncbi_cv_lib_berkeley_db=no])])
   if test "$ncbi_cv_lib_berkeley_db" = "no"; then
      NCBI_MISSING_PACKAGE(bdb)
   else
      AC_CACHE_CHECK([Berkeley DB version (4.3 or newer required)],
         ncbi_cv_lib_berkeley_db_version,
         [AC_LANG_CONFTEST([AC_LANG_SOURCE([[
cat >/dev/null <<_NCBI_EOF
@%:@include <db.h>
_NCBI_EOF
get_DB_VERSION() {
    grep '^[^#]' <<_NCBI_EOF
DB_VERSION_MAJOR.DB_VERSION_MINOR.DB_VERSION_PATCH
_NCBI_EOF
}
ncbi_cv_lib_berkeley_db_version=\`get_DB_VERSION | tr -cd 0123456789.\`
          ]])])
          eval "$ac_cpp $BERKELEYDB_INCLUDE conftest.$ac_ext" > conftest.sh \
             2>&AS_MESSAGE_LOG_FD
          . ./conftest.sh
          rm -f conftest*
         ])
      case "$ncbi_cv_lib_berkeley_db_version" in
         1.* | 2.* | 3.* | 4.[[0-2]].* )
            AC_MSG_WARN(
               [Your Berkeley DB version is too old to use.  (Needed >= 4.3.)])
            if test -n "$with_bdb"; then
               AC_MSG_ERROR([--with-bdb:  Berkeley DB library is too old])
            fi
            with_bdb=no
            ;;
         4.[[3-6]].* | [[5-9]].* | 1[[0-7]].* | 18.[[01]].* ) ;;
         * )
            AC_MSG_WARN(
               [Untested Berkeley DB version; may prove incompatible.])
            AC_MSG_WARN(
               [If so, please re-run this script with the flag --without-bdb.])
            ;;
      esac
   fi
fi
if test "$with_bdb" = "no" ; then
   BERKELEYDB_PATH="No_BerkeleyDB"
   BERKELEYDB_INCLUDE=
   BERKELEYDB_LIBS=
   BERKELEYDB_STATIC_LIBS=
   BERKELEYDB_CXX_LIBS=
   BERKELEYDB_CXX_STATIC_LIBS=
else
   NCBI_PACKAGE(BerkeleyDB)
   AC_DEFINE(HAVE_BERKELEY_DB, 1,
             [Define to 1 if Berkeley DB libraries are available.])
   if test -d "$BERKELEYDB_LIBPATH"; then
      NCBI_RPATHIFY_COND(BERKELEYDB_CXX_LIBS:, ${BERKELEYDB_LIBPATH},
          [ -ldb_cxx -ldb])
   else
      : ${BERKELEYDB_CXX_LIBS:="-ldb_cxx -ldb"}
   fi
   if test -f "${BERKELEYDB_LIBPATH}/libdb_cxx-static.a"; then
      BERKELEYDB_CXX_STATIC_LIBS="-L${BERKELEYDB_LIBPATH} -ldb_cxx-static -ldb-static"
   else
      BERKELEYDB_CXX_STATIC_LIBS=${BERKELEYDB_CXX_LIBS}
   fi
   AC_CACHE_CHECK([for native Berkeley DB C++ wrappers (optional)],
      ncbi_cv_lib_berkeley_db_cxx,
      [CPPFLAGS="$BERKELEYDB_INCLUDE $orig_CPPFLAGS"
       LIBS="$BERKELEYDB_CXX_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <db_cxx.h>]],
          [[DbEnv env(0);  Db db(&env, 0);  db.set_app_private(NULL);]])],
          [ncbi_cv_lib_berkeley_db_cxx=yes],
          [ncbi_cv_lib_berkeley_db_cxx=no])])
   if test "$ncbi_cv_lib_berkeley_db_cxx" = "yes"; then
      NCBI_PACKAGE(BerkeleyDB++)
      AC_DEFINE(HAVE_BERKELEY_DB_CXX, 1,
                [Define to 1 if the Berkeley `db_cxx' library is available.])
   else
      BERKELEYDB_CXX_LIBS=
      BERKELEYDB_CXX_STATIC_LIBS=
   fi
fi


## ODBC
case "$with_odbc" in
   yes | ""   ) : ${ODBC_PATH:=dbapi/driver/odbc/unix_odbc} ;;
   internal | no ) ODBC_PATH=dbapi/driver/odbc/unix_odbc       ;;
   *          ) ODBC_PATH=$with_odbc                        ;;
esac

case "$ODBC_PATH" in
 dbapi/* ) ;;
 *)
   ODBC_INCLUDE="-I$ODBC_PATH/include"
   ODBC_LIBPATH="${ODBC_PATH}/lib"
   NCBI_RPATHIFY(ODBC_LIBS, ${ODBC_LIBPATH}, [ -lodbc -lodbcinst])
   CPPFLAGS="$ODBC_INCLUDE $orig_CPPFLAGS"
   LIBS="$ODBC_LIBS $orig_LIBS"
   AC_CACHE_CHECK([for ODBC libraries${ODBC_PATH:+ in $ODBC_PATH}],
      ncbi_cv_lib_odbc,
      [AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <sql.h>]],
          [[SQLHDBC hdbc;  SQLCHAR* cp = (SQLCHAR*) "x";
            SQLRETURN x = SQLConnect(hdbc, cp, 1, cp, 2, cp, 3);]])],
          [ncbi_cv_lib_odbc=yes], [ncbi_cv_lib_odbc=no])])
   if test "$ncbi_cv_lib_odbc" = "no"; then
      dnl ODBC_PATH=dbapi/driver/odbc/unix_odbc
      dnl AC_MSG_WARN([Falling back to internal FreeTDS-specific ODBC implementation.])
      NCBI_MISSING_PACKAGE(odbc)
   else
      # odbcss.h isn't self-contained :-/
      AC_CHECK_HEADERS(odbcss.h, [], [], [@%:@include <sql.h>])

      AC_CHECK_FUNCS(SQLGetPrivateProfileString)
      AC_CHECK_TYPES([SQLLEN, SQLROWOFFSET, SQLROWSETSIZE, SQLSETPOSIROW],,,
         [@%:@include <sqltypes.h>])
      AC_CHECK_SIZEOF(SQLWCHAR, [], [@%:@include <sqltypes.h>])

      AC_CACHE_CHECK([whether SQLColAttribute's last argument is an SQLLEN *],
         ncbi_cv_func_sqlcolattribute_sqllen,
         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
            [[@%:@include <sql.h>
              SQLRETURN SQL_API SQLColAttribute
                (SQLHSTMT sh, SQLUSMALLINT cn, SQLUSMALLINT fi, SQLPOINTER ca,
                 SQLSMALLINT bl, SQLSMALLINT *sl, SQLLEN *na);]],
            [[]])],
            ncbi_cv_func_sqlcolattribute_sqllen=yes,
            ncbi_cv_func_sqlcolattribute_sqllen=no)])
      if test $ncbi_cv_func_sqlcolattribute_sqllen = yes; then
         AC_DEFINE(NCBI_SQLCOLATTRIBUTE_SQLLEN, 1,
            [Define to 1 if SQLColAttribute's last argument is an SQLLEN *])
      fi
   fi
   ;;
esac

case "$ODBC_PATH" in
 dbapi/*)
   # ODBC_PATH="No_ODBC"
   # Point to a local copy of unixODBC's headers, required by FreeTDS 0.64+.
   ODBC_INCLUDE="-I\$(includedir)/$ODBC_PATH -I\$(includedir0)/$ODBC_PATH"
   ODBC_LIBS=
   dnl AC_DEFINE(HAVE_SQLGETPRIVATEPROFILESTRING, 1)
   AC_DEFINE(HAVE_SQLLEN, 1)
   if test $NCBI_PLATFORM_BITS -eq 32; then
      AC_DEFINE(HAVE_SQLROWOFFSET, 1)
      AC_DEFINE(HAVE_SQLROWSETSIZE, 1)
   fi
   AC_DEFINE(HAVE_SQLSETPOSIROW, 1)
   AC_DEFINE(NCBI_SQLCOLATTRIBUTE_SQLLEN, 1)
   dnl AC_DEFINE(SIZEOF_SQLWCHAR, 2) # depends on SQL_WCHART_CONVERT
   ;;
 *)
   NCBI_PACKAGE(ODBC)
   AC_DEFINE(HAVE_ODBC, 1, [Define to 1 if ODBC libraries are available.])
   ;;
esac

## Python
if test "$with_python" != "no" ; then
   case "$with_python" in
      yes | "" ) ;;
      */*      ) PYTHON_PATH=$with_python ;;
   esac
   NCBI_CHECK_PYTHON()
   NCBI_CHECK_PYTHON(2.5)
   NCBI_CHECK_PYTHON(2.6)
   NCBI_CHECK_PYTHON(2.7)
   NCBI_CHECK_PYTHON(3)
   if test "$ncbi_cv_lib_python" = "no"; then
      if test "$ncbi_cv_lib_python27" = "yes"; then
         PYTHON_INCLUDE=$PYTHON27_INCLUDE
         PYTHON_LIBS=$PYTHON27_LIBS
      elif test "$ncbi_cv_lib_python26" = "yes"; then
         PYTHON_INCLUDE=$PYTHON26_INCLUDE
         PYTHON_LIBS=$PYTHON26_LIBS
      elif test "$ncbi_cv_lib_python25" = "yes"; then
         PYTHON_INCLUDE=$PYTHON25_INCLUDE
         PYTHON_LIBS=$PYTHON25_LIBS
      fi
      if test -n "$PYTHON_LIBS"; then
         NCBI_PACKAGE(PYTHON)
         AC_DEFINE(HAVE_PYTHON, 1)
      else
         NCBI_MISSING_PACKAGE(python)
      fi
   fi
fi

## Perl
if test "$with_perl" != "no" ; then
   case "$with_perl" in
      yes | "" ) ;;
      */*      ) PERL_PATH=$with_perl ;;
   esac
   AC_PATH_PROG(PERL, perl, [], [$PERL_PATH/bin:$PATH])
   if test -x "$PERL"; then
      PERL_ARCHLIB=`$PERL -MConfig -e 'print \$Config{archlibexp};'`
      PERL_FLAGS=`$PERL -MConfig -e 'print join " ", grep /^-[[DI]]/, split /\\s+/, \$Config{cppflags};'`
      PERL_INCLUDE="-I$PERL_ARCHLIB/CORE $PERL_FLAGS"
      PERL_DEPS=`$PERL -MConfig -e '$_ = " \$Config{libs} "; s/ -l\S*db\S*(?= )/ /g; print;'`
      NCBI_RPATHIFY(PERL_LIBS, $PERL_ARCHLIB/CORE, [ -lperl $PERL_DEPS])
      CPPFLAGS="$PERL_INCLUDE $orig_CPPFLAGS"
      LIBS="$PERL_LIBS $orig_LIBS"
      AC_CACHE_CHECK([for usable Perl libraries], [ncbi_cv_lib_perl],
         [AC_LINK_IFELSE([AC_LANG_PROGRAM(
                [[
@%:@include <EXTERN.h>
@%:@include <perl.h>]],
                [[PerlInterpreter* p = perl_alloc();]])],
             [ncbi_cv_lib_perl=yes], [ncbi_cv_lib_perl=no])])
   fi
   if test "$ncbi_cv_lib_perl" = yes; then
      NCBI_PACKAGE(PERL)
      dnl AC_DEFINE(HAVE_PERL, 1)
   else
      NCBI_MISSING_PACKAGE(perl)
      PERL_INCLUDE=
      PERL_LIBS=
   fi
fi

## Java
if test "${with_jni-no}" != "no"; then
   case "$with_jni:${JAVAC+set}" in
      yes: | : )
         if test -d "$JAVA_HOME"; then
            JAVAC=$JAVA_HOME/bin/javac
         else
            JAVAC=javac
         fi
         ;;
      * )
         JAVAC=$with_jni/bin/javac
         ;;
   esac
   AX_JNI_INCLUDE_DIR
   JDK_INCLUDE=''
   sep=''
   for x in $JNI_INCLUDE_DIRS; do
      JDK_INCLUDE=$JDK_INCLUDE$sep-I$x
      sep=' '
   done
   AC_MSG_NOTICE([setting JDK_INCLUDE = $JDK_INCLUDE])
   CPPFLAGS="$JDK_INCLUDE $orig_CPPFLAGS"
   AC_CHECK_HEADER(jni.h,
      [AC_DEFINE(NCBI_JNI, 1,
          [Define to 1 if building Java Native Interface bindings.])
       NCBI_FEATURE([JDK])
       NCBI_FEATURE([Ncbi-JNI])
       JDK_PATH=$_JTOPDIR
       ncbi_java=ncbi_java],
      [JDK_INCLUDE=''
       JDK_PATH=''
       ncbi_java=''])
fi


## Boost
if test "$with_boost" != "no"; then
   if test "${with_boost-yes}" != yes; then
      BOOST_PATH=$with_boost
   fi
   if test -d "$BOOST_PATH"; then
      NCBI_FIX_DIR(BOOST_PATH)
      : ${BOOST_INCLUDE=-I$BOOST_PATH/include}
   fi
   BOOST_LIBPATH_=$BOOST_PATH/lib
   NCBI_RPATHIFY_COND(BOOST_LIBPATH, $BOOST_LIBPATH_)
   if test -d "$BOOST_PATH"; then  
      boost_path_digits=`basename $BOOST_PATH | sed -e 's/-ncbi[[0-9]]*$//; s/.0$//' | tr -cd 0123456789`
   else
      boost_path_digits=
      BOOST_LIBPATH_=/usr/lib
   fi
   if test -n "$boost_path_digits"; then
      boost_version_digits=`echo $ncbi_cv_lib_boost_version | sed -e 's/.0$//' | tr -cd 0123456789`
      if test $boost_path_digits != "$boost_version_digits"; then
         # presumably stale, particularly if boost_version WASN'T cached;
         # uncache all relevant settings
         AS_UNSET(ncbi_cv_lib_boost_version)
         AS_UNSET(ncbi_cv_lib_boost_version_num)
         AS_UNSET(ncbi_cv_lib_boost_regex)
         AS_UNSET(ncbi_cv_lib_boost_spirit)
         AS_UNSET(ncbi_cv_lib_boost_system)
         AS_UNSET(ncbi_cv_lib_boost_filesystem)
         AS_UNSET(ncbi_cv_lib_boost_iostreams)
         AS_UNSET(ncbi_cv_lib_boost_program_options)
         AS_UNSET(ncbi_cv_lib_boost_serialization)
         AS_UNSET(ncbi_cv_lib_boost_test)
         AS_UNSET(ncbi_cv_lib_boost_thread)
      elif test -z "$ncbi_cv_lib_boost_version_num"; then
         AS_UNSET(ncbi_cv_lib_boost_version)
      fi
   fi
      CPPFLAGS=$orig_CPPFLAGS
      AC_CACHE_CHECK([Boost version],
         ncbi_cv_lib_boost_version,
         [AC_LANG_CONFTEST([AC_LANG_SOURCE([[
cat >/dev/null <<_NCBI_EOF
@%:@include <boost/version.hpp>
_NCBI_EOF
get_BOOST_VERSION() {
    grep '^[^#]' <<_NCBI_EOF
BOOST_VERSION
_NCBI_EOF
}
get_BOOST_LIB_VERSION() {
    grep '^[^#]' <<_NCBI_EOF
BOOST_LIB_VERSION
_NCBI_EOF
}
ncbi_cv_lib_boost_version_num=\`get_BOOST_VERSION\`
ncbi_cv_lib_boost_version=\`get_BOOST_LIB_VERSION | tr -d '"'\`
          ]])])
          _AC_DO([$ac_cpp $BOOST_INCLUDE conftest.$ac_ext]) > conftest.sh
          . ./conftest.sh 2>&AS_MESSAGE_LOG_FD
          rm -f conftest*
         ])
      AC_DEFINE_UNQUOTED(NCBI_EXPECTED_BOOST_VERSION,
         $ncbi_cv_lib_boost_version_num,
         [Define to the expected Boost version, to help catch skew.])
   if test -d `echo $BOOST_INCLUDE | sed -e 's/^-I//'`/boost-${ncbi_cv_lib_boost_version}/boost; then
      BOOST_INCLUDE=$BOOST_INCLUDE/boost-${ncbi_cv_lib_boost_version}
   fi
   case "$compiler:$ncbi_compiler_ver" in
      MIPSpro*)
         BOOST_INCLUDE="$BOOST_INCLUDE $BOOST_INCLUDE/boost/compatibility/cpp_c_headers"
         ;;
      WorkShop*)
         # Boost.Test's macros yield a *lot* of spurious "should not initialize
         # a non-const reference with a temporary" warnings, to the point of
         # overwhelming the compiler in some cases; turn them off altogether
         # when using Boost at all.
         BOOST_INCLUDE="$BOOST_INCLUDE -erroff=reftotemp"
         ;;
      GCC* | *Clang* )
         # Some portions of Boost also have a lot of "unused" typedefs
         # from concept checking.
         BOOST_INCLUDE="$BOOST_INCLUDE -Wno-unused-local-typedefs"
         ;;
   esac
   case "$ncbi_cv_lib_boost_version" in
      0_* | 1_[[0-9]] | 1_[[0-9]]_* | 1_[[0-2]][[0-9]] | 1_[[0-2]][[0-9]]_* ) ;;
      1_3[[0-4]] | 1_3[[0-4]]_* )
         AC_MSG_WARN(
            [Your Boost version is too old to use.  (Needed >= 1.35.)])
         if test -n "$with_boost"; then
            AC_MSG_ERROR([--with-boost:  Boost library is too old])
         fi
         with_boost=no
         ;;
      1_3[[5-9]] | 1_3[[5-9]]_* | 1_[[4-7]]* ) ;;
      '' ) with_boost=no ;;
      * )
         AC_MSG_WARN(
            [Untested Boost version; may prove incompatible.])
         AC_MSG_WARN(
            [If so, please re-run this script with the flag --without-boost.])
         ;;
   esac
   AC_MSG_CHECKING([for Boost library name tag])
   case "$with_boost_tag" in
      yes | "" )
         case "$host_os:$ncbi_compiler" in
            darwin*:GCC) BOOST_TAG="-xgcc" ;;
            *:GCC)       BOOST_TAG="-gcc" ;;
            *:KCC)       BOOST_TAG="-kcc" ;;
            linux*:ICC)  BOOST_TAG="-il"  ;;
            *:WORKSHOP)  BOOST_TAG="-sw"  ;;
            *:MIPSPRO)   BOOST_TAG="-mp"  ;;
            *:VISUALAGE) BOOST_TAG="-xlc" ;;
            *:COMPAQ)    BOOST_TAG="-tru" ;;
            *:MSVC)      BOOST_TAG="-vc"  ;;
            darwin*:*CLANG)
               if test "x$ac_cv_have_decl__LIBCPP_VERSION" = xyes; then
                  BOOST_TAG="-clang-darwin"
               else
                  BOOST_TAG="-xgcc"
                  boost_comp_vers=`echo $gccver | tr -d . | cut -c1-2`
               fi
               ;;
            *:*CLANG)
               if test "x$ac_cv_have_decl__LIBCPP_VERSION" = xyes; then
                  BOOST_TAG="-clang"
               else
                  BOOST_TAG="-gcc"
                  boost_comp_vers=`echo $gccver | tr -d . | cut -c1-2`
               fi
               ;;
         esac
         case "$BOOST_TAG:$compiler_version" in
            -*gcc:???|-il:???|-clang*:??? )
               : ${boost_comp_vers=`echo $compiler_version | cut -c1-2`}
               boost_comp_major=`echo $compiler_version | cut -c1`
               ;;
            -*gcc:????|-il:????|-clang*:???? )
               : ${boost_comp_vers=`echo $compiler_version | cut -c1-3`}
               boost_comp_major=`echo $compiler_version | cut -c1-2`
               ;;
            * )
               boost_comp_vers=''
               boost_comp_major=''
               ;;
         esac
         test "$with_mt"    = "yes"  &&  BOOST_MT=-mt
         if test "$with_max_debug" = yes; then
            BOOST_D="-gd -d"
         elif test "$with_debug" = no; then
            BOOST_D=
         else
            BOOST_D=-d
         fi
         test "$bit64_sfx"  = "64"   &&  BOOST_64=-64
         case "$host_cpu" in
            i?86 | x86_64 ) BOOST_ARCH=-x$NCBI_PLATFORM_BITS ;;
            aarch64 | arm*) BOOST_ARCH=-a$NCBI_PLATFORM_BITS ;;
            ia64          ) BOOST_ARCH=-i$NCBI_PLATFORM_BITS ;;
            sparc*        ) BOOST_ARCH=-s$NCBI_PLATFORM_BITS ;;
            mips*         ) BOOST_ARCH=-m$NCBI_PLATFORM_BITS ;;
            power* | ppc* ) BOOST_ARCH=-p$NCBI_PLATFORM_BITS ;;
            *             ) BOOST_ARCH= ;;
         esac
         found=no
         for base in "$BOOST_TAG$boost_comp_vers" \
             "$BOOST_TAG$boost_comp_major" "$BOOST_TAG" ''; do
           for bvers in "-$ncbi_cv_lib_boost_version" ''; do
             for bvers2 in "$BOOST_ARCH$bvers" "$bvers$BOOST_64" "$bvers"; do
               for bmt in "$BOOST_MT" '-mt' ''; do
                 for bd in $BOOST_D '' '-d'; do
                   bsfx=$bmt$bd$bvers2
                   if ls $BOOST_LIBPATH_/libboost*$base$bsfx.* >/dev/null 2>&1;
                   then
                     found=yes
                     break
                   else
                     for ext in .a .so; do
                       name=libboost_system$base$bsfx$ext
                       path=`$CXX -B$BOOST_LIBPATH_/ -print-file-name=$name \
                             2>/dev/null`
                       case "$path" in
                         $BOOST_PATH/*/$name ) found=yes; break ;;
                       esac
                     done
                   fi
                   test "$found" = yes  &&  break
                 done
                 test "$found" = yes  &&  break
               done
               test "$found" = yes  &&  break
             done
             test "$found" = yes  &&  break
           done
           test "$found" = yes  &&  break
         done

         if test "$found" = no; then
            base=$BOOST_TAG
            cvers=$boost_comp_vers
            bvers=-$ncbi_cv_lib_boost_version
            bvers2=$BOOST_ARCH$bvers
            bmt=$BOOST_MT
            bd=${BOOST_D%% *}
            bsfx=$cvers$bmt$bd$bvers2
         fi

         BOOST_TAG=$base$bsfx
         AC_MSG_RESULT([$BOOST_TAG (autodetected)])
         ;;
      no )
         BOOST_TAG=""
         AC_MSG_RESULT([none (by explicit request)])
         ;;
      *)
         BOOST_TAG=$with_boost_tag
         AC_MSG_RESULT([$BOOST_TAG (by explicit request)])
         ;;
   esac
   BOOST_STATIC_TAG=`echo "_$BOOST_TAG-s" \
     | sed -e 's/^_//; s/-\(g*d\)-s$/-s\1/; s/-\(g*d-.*\)-s$/-s\1/; s/\(-[[a-z][36][24]].*\)-s$/-s\1/; s/\(-[[1-9]].*\)-s$/-s\1/'`

   test "$with_mt" = yes  || \
      BOOST_INCLUDE="$BOOST_INCLUDE -DBOOST_DISABLE_THREADS"

   BOOST_REGEX_LIBS=-lboost_regex${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_regex$BOOST_STATIC_TAG.a"; then
       BOOST_REGEX_STATIC_LIBS=-lboost_regex$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           BOOST_REGEX_LIBS=$BOOST_REGEX_STATIC_LIBS
       fi
   else
       BOOST_REGEX_STATIC_LIBS=$BOOST_REGEX_LIBS
   fi

   in_path=${BOOST_PATH:+ in $BOOST_PATH}

   AC_CACHE_CHECK([for Boost.Regex$in_path], ncbi_cv_lib_boost_regex,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_REGEX_LIBS $RT_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/regex.hpp>]],
              [[throw boost::regex_error(boost::regex_constants::error_stack);]])],
          [ncbi_cv_lib_boost_regex=yes], [ncbi_cv_lib_boost_regex=no])])

   AC_CACHE_CHECK([for Boost.Spirit$in_path], ncbi_cv_lib_boost_spirit,
      CPPFLAGS="$BOOST_INCLUDE -DBOOST_ERROR_CODE_HEADER_ONLY $orig_CPPFLAGS"
      LIBS="$RT_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/spirit.hpp>
                             using namespace boost::spirit;
                             struct MyGrammar : public grammar<MyGrammar>
                             {
                                 template <typename TScanner>
                                 struct definition {
                                     definition(const MyGrammar&) { }
                                     typedef rule<TScanner, parser_context<>,
                                                  parser_tag<0> >
                                             TRule;
                                     TRule my_rule;
                                     TRule const & start() const
                                         { return my_rule; }
                                 };
                             };]],
              [[MyGrammar g;  parse("123", g);]])],
          [ncbi_cv_lib_boost_spirit=yes], [ncbi_cv_lib_boost_spirit=no])])

   BOOST_SYSTEM_LIBS=-lboost_system${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_system$BOOST_STATIC_TAG.a"; then
       BOOST_SYSTEM_STATIC_LIBS=-lboost_system$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           BOOST_SYSTEM_LIBS=$BOOST_SYSTEM_STATIC_LIBS
       fi
   else
       BOOST_SYSTEM_STATIC_LIBS=$BOOST_SYSTEM_LIBS
   fi

   AC_CACHE_CHECK([for Boost.System$in_path], ncbi_cv_lib_boost_system,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_SYSTEM_LIBS $RT_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/system/error_code.hpp>]],
              [[const char * s = boost::system::system_category().name();]])],
          [ncbi_cv_lib_boost_system=yes],
          [ncbi_cv_lib_boost_system=no
           BOOST_SYSTEM_LIBS=
           BOOST_SYSTEM_STATIC_LIBS=])])

   boost_chrono_lib=-lboost_chrono${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_chrono$BOOST_STATIC_TAG.a"; then
       boost_chrono_static_lib=-lboost_chrono$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           boost_chrono_lib=$boost_chrono_static_lib
       fi
   else
       boost_chrono_static_lib=$boost_chrono_lib
   fi
   BOOST_CHRONO_LIBS="$boost_chrono_lib $BOOST_SYSTEM_LIBS"
   BOOST_CHRONO_STATIC_LIBS="$boost_chrono_static_lib $BOOST_SYSTEM_STATIC_LIBS"

   AC_CACHE_CHECK([for Boost.Chrono$in_path], ncbi_cv_lib_boost_chrono,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_CHRONO_LIBS $BOOST_SYSTEM_LIBS $RT_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/chrono.hpp>]],
              [[boost::chrono::system_clock::now();]])],
          [ncbi_cv_lib_boost_chrono=yes],
          [ncbi_cv_lib_boost_chrono=no])])

   boost_fs_lib=-lboost_filesystem${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_filesystem$BOOST_STATIC_TAG.a"; then
       boost_fs_static_lib=-lboost_filesystem$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           boost_fs_lib=$boost_fs_static_lib
       fi
   else
       boost_fs_static_lib=$boost_fs_lib
   fi
   BOOST_FILESYSTEM_LIBS="$boost_fs_lib $BOOST_SYSTEM_LIBS"
   BOOST_FILESYSTEM_STATIC_LIBS="$boost_fs_static_lib $BOOST_SYSTEM_STATIC_LIBS"

   AC_CACHE_CHECK([for Boost.Filesystem$in_path], ncbi_cv_lib_boost_filesystem,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_FILESYSTEM_LIBS $RT_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/filesystem.hpp>]],
              [[return boost::filesystem::portable_name("foo");]])],
          [ncbi_cv_lib_boost_filesystem=yes],
          [ncbi_cv_lib_boost_filesystem=no])])

   BOOST_IOSTREAMS_LIBS=-lboost_iostreams${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_iostreams$BOOST_STATIC_TAG.a"; then
       BOOST_IOSTREAMS_STATIC_LIBS=-lboost_iostreams$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           BOOST_IOSTREAMS_LIBS=$BOOST_IOSTREAMS_STATIC_LIBS
       fi
   else
       BOOST_IOSTREAMS_STATIC_LIBS=$BOOST_IOSTREAMS_LIBS
   fi

   AC_CACHE_CHECK([for Boost.Iostreams$in_path], ncbi_cv_lib_boost_iostreams,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_IOSTREAMS_LIBS $Z_LIBS $BZ2_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/iostreams/device/file_descriptor.hpp>]],
              [[boost::iostreams::file_descriptor fd;]])],
          [ncbi_cv_lib_boost_iostreams=yes],
          [ncbi_cv_lib_boost_iostreams=no])])

   BOOST_PROGRAM_OPTIONS_LIBS=-lboost_program_options${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_program_options$BOOST_STATIC_TAG.a"; then
       BOOST_PROGRAM_OPTIONS_STATIC_LIBS=-lboost_program_options$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           BOOST_PROGRAM_OPTIONS_LIBS=$BOOST_PROGRAM_OPTIONS_STATIC_LIBS
       fi
   else
       BOOST_PROGRAM_OPTIONS_STATIC_LIBS=$BOOST_PROGRAM_OPTIONS_LIBS
   fi

   AC_CACHE_CHECK([for Boost.Program-Options$in_path],
      ncbi_cv_lib_boost_program_options,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_PROGRAM_OPTIONS_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/program_options.hpp>]],
              [[boost::program_options::option_description od;]])],
          [ncbi_cv_lib_boost_program_options=yes],
          [ncbi_cv_lib_boost_program_options=no])])

   BOOST_SERIALIZATION_LIBS=-lboost_serialization${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_serialization$BOOST_STATIC_TAG.a"; then
       BOOST_SERIALIZATION_STATIC_LIBS=-lboost_serialization$BOOST_STATIC_TAG
       if test "x$with_bin_release" = "xyes"; then
           BOOST_SERIALIZATION_LIBS=$BOOST_SERIALIZATION_STATIC_LIBS
       fi
   else
       BOOST_SERIALIZATION_STATIC_LIBS=$BOOST_SERIALIZATION_LIBS
   fi

   AC_CACHE_CHECK([for Boost.Serialization$in_path],
      ncbi_cv_lib_boost_serialization,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_SERIALIZATION_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/archive/text_oarchive.hpp>
                             @%:@include <iostream>]],
              [[boost::archive::text_oarchive oa(std::cout);]])],
          [ncbi_cv_lib_boost_serialization=yes],
          [ncbi_cv_lib_boost_serialization=no])])

   BOOST_TEST_PEM_LIBS=-lboost_prg_exec_monitor${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_prg_exec_monitor$BOOST_STATIC_TAG.a"; then
       BOOST_TEST_PEM_STATIC_LIBS=-lboost_prg_exec_monitor$BOOST_STATIC_TAG
   else
       BOOST_TEST_PEM_STATIC_LIBS=$BOOST_TEST_PEM_LIBS
   fi

   BOOST_TEST_TEM_LIBS=-lboost_test_exec_monitor${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_test_exec_monitor$BOOST_STATIC_TAG.a"; then
       BOOST_TEST_TEM_STATIC_LIBS=-lboost_test_exec_monitor$BOOST_STATIC_TAG
   else
       BOOST_TEST_TEM_STATIC_LIBS=$BOOST_TEST_TEM_LIBS
   fi

   BOOST_TEST_UTF_LIBS=-lboost_unit_test_framework${BOOST_TAG}
   if test -f "$BOOST_LIBPATH_/libboost_unit_test_framework$BOOST_STATIC_TAG.a"; then
       BOOST_TEST_UTF_STATIC_LIBS=-lboost_unit_test_framework$BOOST_STATIC_TAG
   else
       BOOST_TEST_UTF_STATIC_LIBS=$BOOST_TEST_UTF_LIBS
   dnl AC_DEFINE([NCBI_BOOST_TEST_DLL], 1,
   dnl   [Define to 1 if unable to locate an appropriate
   dnl    libboost_unit_test_framework$BOOST_STATIC_TAG.a.])
   fi

   BOOST_TEST_PEM_LIBS=$BOOST_TEST_PEM_STATIC_LIBS
   BOOST_TEST_TEM_LIBS=$BOOST_TEST_TEM_STATIC_LIBS
   BOOST_TEST_UTF_LIBS=$BOOST_TEST_UTF_STATIC_LIBS

   AC_CACHE_CHECK([for Boost.Test$in_path], ncbi_cv_lib_boost_test,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$RT_LIBS $orig_LIBS"
      found=
      for mode in included external; do
        if test "$mode" = external; then
          CPPFLAGS="-DNCBI_BOOST_NOT_INCLUDED $CPPFLAGS"
          LIBS="$BOOST_LIBPATH $BOOST_TEST_UTF_LIBS $LIBS"
        fi
        [AC_LINK_IFELSE(
           [AC_LANG_SOURCE(
              [[@%:@ifdef NCBI_BOOST_NOT_INCLUDED
                @%:@  include <boost/test/unit_test.hpp>
                @%:@else
                @%:@  include <boost/test/included/unit_test.hpp>
                @%:@endif
                using boost::unit_test::test_suite;
                static void s_Test1(void) { BOOST_CHECK(1 == 1); }
                test_suite* init_unit_test_suite(int, char*[])
                {
                    test_suite* test = BOOST_TEST_SUITE("foo");
                    test->add(BOOST_TEST_CASE(&s_Test1), 0);
                    return test;
                }]])],
           [found="$found:$mode"])]
      done
      [case "$found" in
        :included:external ) ncbi_cv_lib_boost_test=yes           ;;
        :included          ) ncbi_cv_lib_boost_test=included-only ;;
        :external          ) ncbi_cv_lib_boost_test=external-only ;;
        ''                 ) ncbi_cv_lib_boost_test=no            ;;
      esac])

   BOOST_THREAD_LIBS="-lboost_thread${BOOST_TAG} $BOOST_SYSTEM_LIBS"
   if test -f "$BOOST_LIBPATH_/libboost_thread$BOOST_STATIC_TAG.a"; then
       BOOST_THREAD_STATIC_LIBS="-lboost_thread$BOOST_STATIC_TAG $BOOST_SYSTEM_STATIC_LIBS"
       if test "x$with_bin_release" = "xyes"; then
           BOOST_THREAD_LIBS=$BOOST_THREAD_STATIC_LIBS
       fi
   else
       BOOST_THREAD_STATIC_LIBS=$BOOST_THREAD_LIBS
   fi

   AC_CACHE_CHECK([for Boost.Thread$in_path], ncbi_cv_lib_boost_thread,
      CPPFLAGS="$BOOST_INCLUDE $orig_CPPFLAGS"
      LIBS="$BOOST_LIBPATH $BOOST_THREAD_LIBS $RT_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <boost/thread.hpp>]],
              [[boost::mutex m; boost::mutex::scoped_lock l(m);]])],
          [ncbi_cv_lib_boost_thread=yes], [ncbi_cv_lib_boost_thread=no])])
else
   BOOST_INCLUDE=
   BOOST_LIBPATH=
   BOOST_TAG=
   ncbi_cv_lib_boost_chrono=no
   ncbi_cv_lib_boost_filesystem=no
   ncbi_cv_lib_boost_iostreams=no
   ncbi_cv_lib_boost_program_options=no
   ncbi_cv_lib_boost_regex=no
   ncbi_cv_lib_boost_serialization=no
   ncbi_cv_lib_boost_spirit=no
   ncbi_cv_lib_boost_system=no
   ncbi_cv_lib_boost_test=no
   ncbi_cv_lib_boost_thread=no
fi

if test "$ncbi_cv_lib_boost_chrono" != "no"; then
   AC_DEFINE(HAVE_BOOST_CHRONO, 1,
             [Define to 1 if the `Boost.Chrono' library is available.])
   NCBI_PACKAGE(Boost.Chrono)
else
   boost_chrono_lib=
   boost_chrono_static_lib=
   BOOST_CHRONO_LIBS=
   BOOST_CHRONO_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_filesystem" != "no"; then
   AC_DEFINE(HAVE_BOOST_FILESYSTEM, 1,
             [Define to 1 if the `Boost.Filesystem' library is available.])
   NCBI_PACKAGE(Boost.Filesystem)
else
   boost_fs_lib=
   boost_fs_static_lib=
   BOOST_FILESYSTEM_LIBS=
   BOOST_FILESYSTEM_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_iostreams" != "no"; then
   AC_DEFINE(HAVE_BOOST_IOSTREAMS, 1,
             [Define to 1 if the `Boost.Iostreams' library is available.])
   NCBI_PACKAGE(Boost.Iostreams)
else
   BOOST_IOSTREAMS_LIBS=
   BOOST_IOSTREAMS_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_program_options" != "no"; then
   AC_DEFINE(HAVE_BOOST_PROGRAM_OPTIONS, 1,
             [Define to 1 if the `Boost.Program-Options' library is available.])
   NCBI_PACKAGE(Boost.Program-Options)
else
   BOOST_PROGRAM_OPTIONS_LIBS=
   BOOST_PROGRAM_OPTIONS_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_regex" != "no"; then
   AC_DEFINE(HAVE_BOOST_REGEX, 1,
             [Define to 1 if the `Boost.Regex' library is available.])
   NCBI_PACKAGE(Boost.Regex)
else
   BOOST_REGEX_LIBS=
   BOOST_REGEX_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_serialization" != "no"; then
   AC_DEFINE(HAVE_BOOST_SERIALIZATION, 1,
             [Define to 1 if the `Boost.Serialization' library is available.])
   NCBI_PACKAGE(Boost.Serialization)
else
   BOOST_SERIALIZATION_LIBS=
   BOOST_SERIALIZATION_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_spirit" != "no"; then
   AC_DEFINE(HAVE_BOOST_SPIRIT, 1,
             [Define to 1 if the `Boost.Spirit' headers are available.])
   NCBI_PACKAGE(Boost.Spirit)
fi

if test "$ncbi_cv_lib_boost_system" != "no"; then
   AC_DEFINE(HAVE_BOOST_SYSTEM, 1,
             [Define to 1 if the `Boost.System' library is available.])
   NCBI_PACKAGE(Boost.System)
# BOOST_SYSTEM(_STATIC)_LIBS already conditionally cleared above
fi

if test "$ncbi_cv_lib_boost_test" != "no"; then
   AC_DEFINE(HAVE_BOOST_TEST, 1,
             [Define to 1 if the `Boost.Test' libraries are available.])
   if test "$ncbi_cv_lib_boost_test" != "included-only"; then
      NCBI_PACKAGE(Boost.Test)
   fi
   if test "$ncbi_cv_lib_boost_test" != "external-only"; then
      NCBI_PACKAGE(Boost.Test.Included)
   fi
else
   BOOST_TEST_PEM_LIBS=
   BOOST_TEST_PEM_STATIC_LIBS=
   BOOST_TEST_TEM_LIBS=
   BOOST_TEST_TEM_STATIC_LIBS=
   BOOST_TEST_UTF_LIBS=
   BOOST_TEST_UTF_STATIC_LIBS=
fi

if test "$ncbi_cv_lib_boost_thread" != "no"; then
   AC_DEFINE(HAVE_BOOST_THREAD, 1,
             [Define to 1 if the `Boost.Thread' library is available.])
   NCBI_PACKAGE(Boost.Thread)
else
   BOOST_THREAD_LIBS=
   BOOST_THREAD_STATIC_LIBS=
fi

case "$with_boost:$ncbi_cv_lib_boost_test" in
   :* | no:* | *:yes | *:included-only ) ;; # no problem
   * ) AC_MSG_ERROR([Boost explicitly requested, but Boost.Test.Included unavailable.]) ;;
esac


## NCBI C Toolkit
if test "$with_ncbi_c" != "no" ; then
   if test "${with_ncbi_c-yes}" != yes; then
      NCBI_C_PATH=$with_ncbi_c
   fi
   : ${NCBI_C_PATH="$NCBI"}
   if test "$ncbi_compiler" = ICC -a -d "$NCBI_C_PATH/ncbi_icc"; then
      NCBI_C_PATH=$NCBI_C_PATH/ncbi_icc
   fi
   if test -n "$NCBI_C_PATH_TAGS"; then
      for x in $NCBI_C_PATH_TAGS; do
         if test -d "$NCBI_C_PATH$x"; then
            NCBI_C_PATH=$NCBI_C_PATH$x
            break
         fi
      done
   fi

   NCBI_C_INCLUDE="-I$NCBI_C_PATH/include${bit64_sfx}"
   if test "$want_gi32" = "yes"; then
     NCBI_C_INCLUDE="$NCBI_C_INCLUDE -DUSE_BIGINT_IDS=0"
   else
     NCBI_C_INCLUDE="$NCBI_C_INCLUDE -DUSE_BIGINT_IDS=1"
   fi
   if test "$with_debug" = "no" ; then
     NCBI_C_LIBPATH="$NCBI_C_PATH/lib${bit64_sfx}"
   else
     NCBI_C_LIBPATH="$NCBI_C_PATH/altlib${bit64_sfx}"
   fi
   if test "$with_mt" = "yes" ; then
     NCBI_C_LIBPATH="$NCBI_C_LIBPATH $NCBI_C_LIBPATH/ncbithr.o"
   fi
   if test -n "$NCBI_C_ncbi" ; then
     :
   elif test "$OSTYPE" = "darwin" ; then
     NCBI_C_ncbi="-lncbi -Wl,-framework,AppKit"
   else
     NCBI_C_ncbi="-lncbi"
   fi
   NCBI_C_LIBPATH="-L$NCBI_C_LIBPATH"
   AC_CACHE_CHECK([for the NCBI C toolkit${NCBI_C_PATH:+ in $NCBI_C_PATH}],
      ncbi_cv_lib_ctools,
      [CPPFLAGS="$NCBI_C_INCLUDE $orig_CPPFLAGS"
       LIBS="$NCBI_C_LIBPATH $NCBI_C_ncbi $NETWORK_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <ncbi.h>]],
          [[ Nlm_Boolean b = Nlm_GetArgs("fake", -1, 0); ]])],
          [ncbi_cv_lib_ctools=yes], [ncbi_cv_lib_ctools=no])])
   if test "$ncbi_cv_lib_ctools" = no; then
      NCBI_MISSING_PACKAGE(ncbi-c)
   fi
fi
if test "$with_ncbi_c" = "no" ; then
   if test "$with_ctools" = "yes"; then
      AC_MSG_ERROR([--with-ctools:  NCBI C Toolkit is missing])
   fi
   NCBI_C_PATH="No_NCBI_CToolkit"
   NCBI_C_INCLUDE=
   NCBI_C_LIBPATH=
   NCBI_C_ncbi=
else
   NCBI_PACKAGE(C-Toolkit)
   AC_DEFINE(HAVE_NCBI_C, 1, [Define to 1 if the NCBI C toolkit is available.])
fi


### ncbicrypt
case "$with_ncbicrypt" in
   yes | no | '' ) ;;
   *             ) NCBICRYPT_PATH=$with_ncbicrypt ;;
esac
if test -d "$NCBICRYPT_PATH"; then
   NCBI_FIND_ARCH_PATH(NCBICRYPT)
   NCBICRYPT_PATH=$NCBICRYPT_ARCH_PATH
   NCBI_FIX_DIR(NCBICRYPT_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(ncbicrypt,
   [AC_LANG_PROGRAM([[@%:@include <ncbicrypt.h>]],
      [[NCBICRYPT_Key k = NCBICRYPT_Init("foo");]])])
NETWORK_LIBS="$NETWORK_LIBS $NCBICRYPT_LIBS"
NETWORK_PURE_LIBS="$NETWORK_PURE_LIBS $NCBICRYPT_LIBS"


# X11
LIBS="$orig_LIBS"
CPPFLAGS="$orig_CPPFLAGS"
# Look in /usr/X11R6/lib64 if necessary
xlib=`ls -d /usr/X11R6/lib$bit64_sfx/libX11.* 2>/dev/null | sed -ne 1p`
if test -f "$xlib" -a "${x_libraries-NONE}" = NONE \
  -a "${x_includes-NONE}" = NONE; then
   base=`basename $xlib`
   cmp -s /usr/X11R6/lib/$base $xlib  || \
      cmp -s /usr/lib/$base $xlib  || \
      cmp -s /usr/lib$bit64_sfx/$base $xlib  || \
      x_libraries=/usr/X11R6/lib$bit64_sfx x_includes=/usr/X11R6/include
fi
AC_PATH_XTRA
x_libraries=`echo "$x_libraries" | sed -e "s,^$usr_lib\$,,"`
X_LIBS=`echo "$X_LIBS " | sed -e "$no_usr_lib"`
AC_CHECK_LIB(Xext, XextCreateExtension, Xext="-lXext", Xext=,
   [$X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
AC_CHECK_LIB(Xt, XtMainLoop, Xt="-lXt", Xt=,
   [$Xext $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
AC_CHECK_LIB(Xmu, XmuMakeAtom, Xmu="-lXmu", Xmu=,
   [$Xt $Xext $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
LDFLAGS=$orig_LDFLAGS
X_ALL_LIBS="$Xmu $Xt $Xext $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"

## OpenGL
if test "$with_opengl" != "no"; then
   if test "${with_opengl-yes}" != yes; then
      OPENGL_PATH=$with_opengl
   fi
   if test -d "$OPENGL_PATH"; then
      NCBI_FIX_DIR(OPENGL_PATH)
   fi
   case "$OSTYPE" in
      darwin) # Use native interface
         OPENGL_LIBS="-framework AGL -framework GLKit -framework OpenGL"
         # ... and its proprietary successor
         OPENGL_LIBS="$OPENGL_LIBS -framework Metal -framework MetalKit"
         OPENGL_LIBS="$OPENGL_LIBS -framework QuartzCore"
         ;;
      # cygwin) ... ;;
      *) # Default -- assume X-based
         LIBS="$orig_LIBS"
         CPPFLAGS="$orig_CPPFLAGS"
         LDFLAGS="$orig_LDFLAGS $X_LIBS"
         if test -d "$OPENGL_PATH/include/GL"; then
            OPENGL_INCLUDE="-I$OPENGL_PATH/include $X_CFLAGS"
         else
            OPENGL_INCLUDE=$X_CFLAGS
         fi
         if test -n "$OPENGL_PATH" -a -d "$OPENGL_PATH/lib${bit64_sfx}"; then
            NCBI_RPATHIFY(OPENGL_LIBPATH, $OPENGL_PATH/lib${bit64_sfx},
                          [ ]$X_LIBS)
         elif test -f /usr/lib/mesa/libGL.so; then
            NCBI_RPATHIFY(OPENGL_LIBPATH, /usr/lib/mesa, [ ]$X_LIBS)
         else
            OPENGL_LIBPATH=$X_LIBS
         fi
         OPENGL_LIBS="$OPENGL_LIBPATH -lGLU -lGL $X_ALL_LIBS"
         ;;
   esac
   case "${OPENGL_PATH}" in
      */*) where=" in $OPENGL_PATH" ;;
      *  ) where= ;;
   esac
   AC_CACHE_CHECK([for OpenGL$where], ncbi_cv_lib_opengl,
      [CPPFLAGS="$orig_CPPFLAGS $OPENGL_INCLUDE"
       LIBS="$OPENGL_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[
           @%:@ifdef NCBI_OS_DARWIN
           @%:@  include <OpenGL/gl.h>
           @%:@else
           @%:@  include <GL/gl.h>
           @%:@endif
          ]],
          [[glBegin(0);]])],
          [ncbi_cv_lib_opengl=yes], [ncbi_cv_lib_opengl=no])])
fi

if test "$with_opengl" = "no" -o "$ncbi_cv_lib_opengl" = "no"; then
   OPENGL_INCLUDE=
   OPENGL_LIBS=
   OPENGL_STATIC_LIBS=
   OSMESA_INCLUDE=
   OSMESA_LIBS=
   OSMESA_STATIC_LIBS=
   GLUT_INCLUDE=
   GLUT_LIBS=
   GLEW_INCLUDE=
   GLEW_LIBS=
   GLEW_STATIC_LIBS=
   NCBI_MISSING_PACKAGE(opengl)
   NCBI_MISSING_PACKAGE(gl2ps)
else
   NCBI_PACKAGE(OpenGL)
   AC_DEFINE(HAVE_OPENGL, 1, [Define to 1 if you have OpenGL (-lGL).])
   if test -f "$OPENGL_PATH/lib${bit64_sfx}/libGLU-static.a"; then
      OPENGL_STATIC_LIBS="$OPENGL_LIBPATH -lGLU-static -lGL-static $X_ALL_LIBS"
   else
      OPENGL_STATIC_LIBS=$OPENGL_LIBS
   fi
   : ${OSMESA_PATH=$OPENGL_PATH}
   if test "$with_mesa" != "no"; then
      if test "${with_mesa-yes}" != "yes"; then
         OSMESA_PATH=$with_mesa
      fi
      if test -d "$OSMESA_PATH"; then
         OSMESA_INCLUDE=-I$OSMESA_PATH/include
         if test "$OSMESA_PATH" != "$OPENGL_PATH"; then
            NCBI_RPATHIFY(OSMESA_LDFLAGS, $OSMESA_PATH/lib${bit64_sfx})
         fi
      fi
      LDFLAGS="$orig_LDFLAGS $OSMESA_LDFLAGS $OPENGL_LIBPATH"
      AC_CHECK_LIB(OSMesa, OSMesaCreateContext,
         [NCBI_PACKAGE(MESA);
          OSMESA_LIBS="$OSMESA_LDFLAGS $OPENGL_LIBPATH -lOSMesa -lGLU -lGL $X_ALL_LIBS"
          AC_DEFINE(HAVE_LIBOSMESA, 1, [Define to 1 if you have libOSMesa.])],
         [OSMESA_LIBS=],
         $OPENGL_LIBS)
   fi
   if test -z "$OSMESA_LIBS"; then
      NCBI_MISSING_PACKAGE(mesa)
   elif test -f "$OSMESA_PATH/lib${bit64_sfx}/libOSMesa-static.a"; then
      OSMESA_STATIC_LIBS="$OSMESA_LDFLAGS $OPENGL_LIBPATH -lOSMesa-static -lGLU-static -lGL-static $X_ALL_LIBS"
   else
      OSMESA_STATIC_LIBS=$OSMESA_LIBS
   fi
   if test "$with_glut" != "no"; then
      if test "${with_glut-yes}" != "yes"; then
         GLUT_PATH=$with_glut
      fi
      if test -d "GLUT_PATH"; then
         GLUT_INCLUDE=-I$GLUT_PATH/include
         NCBI_RPATHIFY(GLUT_LDFLAGS, $GLUT_PATH/lib${bit64_sfx})
      fi
      LDFLAGS="$orig_LDFLAGS $GLUT_LDFLAGS $OPENGL_LIBPATH"
      AC_CHECK_LIB(glut, glutInit,
         [NCBI_PACKAGE(GLUT);
          GLUT_LIBS="$GLUT_LDFLAGS $OPENGL_LIBPATH -lglut -lGLU -lGL $X_ALL_LIBS"
          AC_DEFINE(HAVE_LIBGLUT, 1, [Define to 1 if you have libglut.])],
         [GLUT_LIBS=],
         $OPENGL_LIBS)
      if test -z "$GLUT_LIBS"; then
         NCBI_MISSING_PACKAGE(glut)
      fi
   fi
   if test "$with_glew" != "no"; then
      if test "${with_glew-yes}" != "yes"; then
         GLEW_PATH=$with_glew
      fi
      if test -d "$GLEW_PATH"; then
         if test -d "$GLEW_PATH/$compiler_vpfx$DEBUG_SFX$bit64_sfx"; then
            GLEW_PATH=$GLEW_PATH/$compiler_vpfx$DEBUG_SFX$bit64_sfx
         elif test -d "$GLEW_PATH/$compiler_pfx$DEBUG_SFX$bit64_sfx"; then
            GLEW_PATH=$GLEW_PATH/$compiler_pfx$DEBUG_SFX$bit64_sfx
         elif test -d "$GLEW_PATH/$DEBUG_SFX$bit64_sfx"; then
            GLEW_PATH=$GLEW_PATH/$DEBUG_SFX$bit64_sfx
         fi
         NCBI_FIX_DIR(GLEW_PATH)
         GLEW_LIBDIR=$GLEW_PATH/lib
         if test -n "$bit64_sfx" -a -d $GLEW_LIBDIR$bit64_sfx; then
            if test -d $GLEW_LIBDIR; then
               for x in $GLEW_LIBDIR/libGLEW*; do
                  if cmp -s "$x" "$GLEW_LIBDIR$bit64_sfx/`basename \"$x\"`"; then
                     :
                  else
                     GLEW_LIBDIR=$GLEW_LIBDIR$bit64_sfx
                     break
                  fi
               done
            else
               GLEW_LIBDIR=$GLEW_LIBDIR$bit64_sfx
            fi
         fi
      fi
      glew_config="eval PKG_CONFIG_PATH=\"$GLEW_LIBDIR/pkgconfig\" pkg-config"
      if pkg-config --version >/dev/null 2>&1; then
         if test "$with_glew_mx" != no \
           && $glew_config glewmx --exists >/dev/null 2>&1 \
           && test -n "`$glew_config glewmx --libs 2>/dev/null`"; then
            glew_config="$glew_config glewmx"
         elif $glew_config glew --exists >/dev/null 2>&1 \
           && test -n "`$glew_config glew --libs 2>/dev/null`"; then
            glew_config="$glew_config glew"
         else
            glew_config=
         fi
         if test -n "$glew_config"; then
            GLEW_INCLUDE=`$glew_config --cflags | sed 's:/GL *$::'`
            GLEW_LDFLAGS=`$glew_config --libs-only-L`
            glew_libname=`$glew_config --libs-only-l | sed -e 's/-l//'`
         fi
      fi
      if test -z "$glew_libname" -a -d "$GLEW_PATH"; then
         GLEW_INCLUDE=-I$GLEW_PATH/include
         GLEW_LDFLAGS=-L$GLEW_LIBDIR
      fi
      LDFLAGS="$orig_LDFLAGS $GLEW_LDFLAGS"
      LIBS="$OPENGL_LIBS $orig_LIBS"
      NCBI_CHECK_LIBS(GLEW, [$glew_libname GLEWmx GLEW], glewGetExtension)
      if test "$ac_cv_search_glewGetExtension" = no; then
         GLEW_INCLUDE=
         GLEW_LIBS=
         NCBI_MISSING_PACKAGE(glew)
         NCBI_MISSING_PACKAGE(glew-mx)
      else
         NCBI_RPATHIFY_OUTPUT_COND(tmp_LIBS, [echo $GLEW_LDFLAGS $GLEW_LIBS])
         GLEW_LIBS=$tmp_LIBS
         NCBI_PACKAGE(GLEW)
         CPPFLAGS="$orig_CPPFLAGS $GLEW_INCLUDE $OPENGL_INCLUDE"
         LIBS="$GLEW_LIBS $OPENGL_LIBS $orig_LIBS"
         AC_CACHE_CHECK([for GLEW multi-context (MX) support],
            ncbi_cv_lib_glew_mx,
            [AC_LINK_IFELSE([AC_LANG_PROGRAM(
               [[@%:@define GLEW_MX 1
                 @%:@include <GL/glew.h>]],
               [[glewContextInit(NULL);]])],
             [ncbi_cv_lib_glew_mx=yes], [ncbi_cv_lib_glew_mx=no])])
          if test $ncbi_cv_lib_glew_mx = yes; then
             if test "$with_glew_mx" = no; then
                GLEW_INCLUDE=
                GLEW_LIBS=
                NCBI_MISSING_PACKAGE(glew)
             else
                GLEW_INCLUDE="$GLEW_INCLUDE -DGLEW_MX"
             fi
          else
             NCBI_MISSING_PACKAGE(glew-mx)
          fi
          : ${GLEW_STATIC_LIBS=$GLEW_LIBDIR/libGLEW-static.a}
          test -f "$GLEW_STATIC_LIBS"  ||  GLEW_STATIC_LIBS=$GLEW_LIBS
      fi
   fi
fi

LDFLAGS=$orig_LDFLAGS


## wxWidgets
# : ${with_wxwidgets_ucs=no}
if test "$with_wxwidgets" != "no" ; then
   case "$with_wxwidgets" in
      yes | "" ) ;;
      *        ) WXWIDGETS_PATH=$with_wxwidgets ;;
   esac
   if test -d "$WXWIDGETS_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}/lib" \
        -a -z "$WXWIDGETS_ARCH_PATH"; then
      WXWIDGETS_ARCH_PATH="$WXWIDGETS_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}"
   elif test -d "$WXWIDGETS_PATH/${compiler_pfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}/lib" \
        -a -z "$WXWIDGETS_ARCH_PATH"; then
      WXWIDGETS_ARCH_PATH="$WXWIDGETS_PATH/${compiler_pfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}"
   else
      WXWIDGETS_ARCH_PATH="$WXWIDGETS_PATH"
   fi
   WXWIDGETS_BINPATH=${WXWIDGETS_BINPATH:="$WXWIDGETS_ARCH_PATH/bin"}
   WXWIDGETS_LIBPATH=${WXWIDGETS_LIBPATH:="$WXWIDGETS_ARCH_PATH/lib"}
   WXWIDGETS_INCLUDE=
   AS_UNSET(wxconf)
   AC_PATH_PROG(wxconf, wx-config, [], $WXWIDGETS_BINPATH:$PATH)
   if test -x "$wxconf"; then
      WXWIDGETS_ARCH_PATH=`$wxconf --exec-prefix`
      if test -n "$with_wxwidgets_ucs"; then
         wxcfflags=--unicode=$with_wxwidgets_ucs
      else
         wxcfflags=
      fi
      for x in `"$wxconf" $wxcfflags --libs --static 2>&AS_MESSAGE_LOG_FD`; do
         case "$x" in
            -L*)
                d=`echo $x | sed -e 's/^-L//'`
                pcd=$d/pkgconfig
                if test -d "$pcd"; then
                   PKG_CONFIG_PATH="${PKG_CONFIG_PATH+$PKG_CONFIG_PATH:}$pcd"
                fi
                ;;
         esac
      done
      export PKG_CONFIG_PATH
   else
      AS_UNSET(wxconf)
   fi
   if test -x "$wxconf" \
     &&  "$wxconf" $wxcfflags --list 2>/dev/null \
       | grep 'Default config is gtk2' >/dev/null; then
      gtkconf="pkg-config gtk+-2.0"
   elif test -x "$wxconf" \
     &&  "$wxconf" $wxcfflags --list 2>/dev/null \
       | grep 'Default config is gtk3' >/dev/null; then
      gtkconf="pkg-config gtk+-3.0"
   elif test -x "$wxconf" \
     &&  "$wxconf" $wxcfflags --list 2>/dev/null \
       | grep 'Default config is gtk4' >/dev/null; then
      gtkconf="pkg-config gtk4"
   elif test -x "$WXWIDGETS_BINPATH/gtk-config"; then
      gtkconf=$WXWIDGETS_BINPATH/gtk-config
   elif gtk-config --version >/dev/null 2>&1; then
      gtkconf=gtk-config
   else
      # May work without gtk-config (e.g., on Mac OS X)
      gtkconf=:
   fi
   case "$host_os" in
      darwin* )
         baseflags=""
         basesed='s/-isysroot [[^ ]]*//g; s/-arch [[^ ]]*//g'
         if test -n "$SYSROOT"; then
            deps=`"$wxconf" $wxcfflags --libs --static 2>/dev/null \
                  | sed -e 's/.*\.a//'`
            libsed="$basesed; s%\$% $deps%"
         else
            libsed=$basesed
         fi
         ;;
      * )
         baseflags=`$gtkconf --cflags 2>/dev/null`
         basesed=$no_usr_lib
         deps=`$gtkconf --libs 2>/dev/null`
         libsed="$basesed; s%\$% $deps%"
         ;;
   esac
   test -x "$wxconf"  &&  case "`"$wxconf" $wxcfflags --version`" in
      1.* | 2.[[0-7]].* ) wxlibs=std ;;
      *                 ) wxlibs=std,richtext,aui,propgrid ;;
   esac
   AC_CACHE_CHECK(
      [for wxWidgets${WXWIDGETS_ARCH_PATH:+ in $WXWIDGETS_ARCH_PATH}],
      ncbi_cv_lib_wxwidgets,
      [if test -x "$wxconf" ; then
          WXWIDGETS_INCLUDE="`"$wxconf" $wxcfflags --cflags` $baseflags"
          NCBI_RPATHIFY_OUTPUT(WXWIDGETS_LIBS,
             ["$wxconf" $wxcfflags --libs $wxlibs],
             [$libsed; s/ -lm / /g;])

          CPPFLAGS="$WXWIDGETS_INCLUDE $orig_CPPFLAGS"
          LIBS="$WXWIDGETS_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
             [[@%:@include <wx/combobox.h>
               class CMyComboBox : public wxComboBox {};]],
             [[CMyComboBox cb; cb.Clear();]])],
             [ncbi_cv_lib_wxwidgets=yes], [ncbi_cv_lib_wxwidgets=no])
       else
          ncbi_cv_lib_wxwidgets=no
       fi])
   if test "$ncbi_cv_lib_wxwidgets" = "no"; then
      NCBI_MISSING_PACKAGE(wxwidgets)
   fi
fi

if test "$with_wxwidgets" = "no" ; then
   WXWIDGETS_LIBPATH="No_wxWidgets"
   WXWIDGETS_INCLUDE=
   WXWIDGETS_LIBS=
   WXWIDGETS_STATIC_LIBS=
   WXWIDGETS_GL_LIBS=
   WXWIDGETS_GL_STATIC_LIBS=
   WXWIDGETS_POST_LINK=:
else
   NCBI_PACKAGE(wxWidgets)
   case "`"$wxconf" $wxcfflags --version`" in
      1.* | 2.[[0-7]].*) ;;
      * ) NCBI_PACKAGE(wx2.8) ;;
   esac
   # The "yes" may have been cached; get the actual settings again if needed
   if test -z "$WXWIDGETS_INCLUDE"; then
      WXWIDGETS_INCLUDE="`"$wxconf" $wxcfflags --cflags` $baseflags"
   fi
   NCBI_RPATHIFY_OUTPUT(WXWIDGETS_LIBS, [$wxconf $wxcfflags --libs $wxlibs],
      [$libsed; s/ -lm / /g;])
   WXWIDGETS_STATIC_LIBS=`"$wxconf" $wxcfflags --libs $wxlibs --static \
      2>/dev/null | sed -e "$basesed; s/ -lm / /g;"`
   if test -n "$WXWIDGETS_STATIC_LIBS"; then
      # Allow direct use of underlying libraries with strict linkers
      WXWIDGETS_LIBS="$WXWIDGETS_LIBS `echo $WXWIDGETS_STATIC_LIBS | sed -e 's/.*\.a *//'`"
   else
      WXWIDGETS_STATIC_LIBS=$WXWIDGETS_LIBS
   fi
   WXWIDGETS_GL_LIBS=`"$wxconf" $wxcfflags --libs gl | sed -e "$basesed"`
   WXWIDGETS_GL_STATIC_LIBS=`"$wxconf" $wxcfflags --libs gl --static \
      2>/dev/null | sed -e "$basesed; s|-lGLU* -lGLU*|$OPENGL_STATIC_LIBS|"`
   : ${WXWIDGETS_GL_STATIC_LIBS:=$WXWIDGETS_GL_LIBS}
   WXWIDGETS_POST_LINK=`"$wxconf" $wxcfflags --rezflags 2>/dev/null`
   test -n "$WXWIDGETS_POST_LINK"  ||  WXWIDGETS_POST_LINK=:
   wxpnglib=$WXWIDGETS_ARCH_PATH/lib/libpng.so
   defpnglib=${PNG_PATH-/usr}/lib${bit64_sfx}/libpng.so
   if test -f $wxpnglib  &&  \
       (test ! -f $defpnglib  ||  ! cmp -s $wxpnglib $defpnglib); then
      PNG_PATH=$WXWIDGETS_ARCH_PATH
      PNG_INCLUDE=$WXWIDGETS_INCLUDE
   fi
   wxtifflib=$WXWIDGETS_ARCH_PATH/lib/libtiff.so
   deftifflib=${TIFF_PATH-/usr}/lib${bit64_sfx}/libtiff.so
   if test -f $wxtifflib  &&  \
       (test ! -f $deftifflib  ||  ! cmp -s $wxtifflib $deftifflib); then
      TIFF_PATH=$WXWIDGETS_ARCH_PATH
      TIFF_INCLUDE=$WXWIDGETS_INCLUDE
   fi
   AC_DEFINE(HAVE_WXWIDGETS, 1, [Define to 1 if wxWidgets is available.])
fi


## In-house Fast-CGI library
if test "$with_fastcgi" != "no" ; then
   case "$with_fastcgi" in
      yes | "" ) ;;
      */*      ) FASTCGI_PATH=$with_fastcgi              ;;
      *        ) FASTCGI_PATH=$NCBI/fcgi-${with_fastcgi} ;;
   esac
   if test -d "$FASTCGI_PATH"; then
      NCBI_FIX_DIR(FASTCGI_PATH)
      NCBI_FIND_ARCH_PATH(FASTCGI)
   fi
   FASTCGI_INCLUDE="-I$FASTCGI_PATH/include"
   if test "$with_debug" != "no" \
      -a -d "$FASTCGI_ARCH_PATH/altlib${bit64_sfx}"; then
      FASTCGI_LIBDIR="$FASTCGI_ARCH_PATH/altlib${bit64_sfx}"
   else
      FASTCGI_LIBDIR="$FASTCGI_ARCH_PATH/lib${bit64_sfx}"
   fi
   NCBI_FIX_DIR(FASTCGI_LIBDIR)
   NCBI_RPATHIFY(FASTCGI_LIBS, $FASTCGI_LIBDIR, [ -lfcgi $NETWORK_LIBS])
   FASTCGI_OBJS="fcgibuf"
   LIBS="$FASTCGI_LIBS $orig_LIBS"
   AC_CACHE_CHECK([for FastCGI libraries${FASTCGI_PATH:+ in $FASTCGI_PATH}],
      ncbi_cv_lib_fcgi,
      [CPPFLAGS="$FASTCGI_INCLUDE $orig_CPPFLAGS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <fcgiapp.h>]],
          [[ (void) FCGX_IsCGI(); ]])],
          [ncbi_cv_lib_fcgi=yes], [ncbi_cv_lib_fcgi=no])])
   if test "$ncbi_cv_lib_fcgi" = "no"; then
      NCBI_MISSING_PACKAGE(fastcgi)
   fi
   AC_CHECK_FUNCS(FCGX_Accept_r)
fi
if test "$with_fastcgi" = "no" ; then
   FASTCGI_PATH="No_FastCgi"
   FASTCGI_INCLUDE=
   FASTCGI_LIBS=
   FASTCGI_OBJS=
else
   NCBI_PACKAGE(Fast-CGI)
   AC_DEFINE(HAVE_LIBFASTCGI, 1,
             [Define to 1 if FastCGI libraries are available.])
fi


## FastCGI++ (MT-capable)
case "$with_fastcgipp" in
   yes | no | '' ) ;;
   *             ) FASTCGIPP_PATH=$with_fastcgipp ;;
esac
if test -d "$FASTCGIPP_PATH"; then
   NCBI_FIND_ARCH_PATH(FASTCGIPP)
   FASTCGIPP_PATH=$FASTCGIPP_ARCH_PATH
   NCBI_FIX_DIR(FASTCGIPP_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(fastcgipp,
  [AC_LANG_PROGRAM([[@%:@include <fastcgi++/http.hpp>]],
      [[Fastcgipp::Http::SessionId sid;]])])


## NCBI SSS libraries
if test "$with_sybase" = "no" ; then
   NCBI_MISSING_PACKAGE(sssdb)
fi

case "$host_os:$compiler:$compiler_version" in
   linux*:GCC:* | linux*:*Clang:* )
      : ${with_included_sss=yes}
   ;;
esac

if test "$with_sss" != "no" ; then
   local_sss=${real_srcdir}/src/internal/sss
   if test "${with_included_sss-no}" = "yes" \
       -a -f "$local_sss/utils/sssdebug.hpp" \
       -a -f "${local_sss}srv/cli/sssconnection.cpp"; then
      with_included_sss=yes
      NCBI_SSS_PATH=$local_sss
      NCBI_SSS_INCLUDE="\$(incdir)/sss"
      NCBI_SSS_LIBPATH="\$(libdir)"
      NCBI_PACKAGE(LocalSSS)
      if test -f "$local_sss/../msgmail2/asn/msgmail.asn"; then
         NCBI_PACKAGE(LocalMSGMAIL2)
      fi
   else
      with_included_sss=no
   fi
   if test "${with_sss-yes}" = yes; then
      NCBI_SSS_PATH=${NCBI_SSS_PATH:="$NCBI/sss/BUILD"}
   else
      NCBI_SSS_PATH=$with_sss
   fi
   NCBI_SSS_INCLUDE=${NCBI_SSS_INCLUDE:="$NCBI_SSS_PATH/include"}
   if test -z "$NCBI_SSS_LIBPATH" ; then
      NCBI_SSS_LIBPATH="${NCBI_SSS_PATH}/lib/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}"
      if test "$with_mt" = "yes" ; then
         NCBI_SSS_LIBPATH="${NCBI_SSS_LIBPATH}mt"
      fi
   fi
   AC_MSG_CHECKING(
      [for NCBI SSS directories${NCBI_SSS_PATH:+ in $NCBI_SSS_PATH}])
   if test "$with_included_sss" = "yes"; then
      AC_MSG_RESULT([yes]) # duh
   elif test ! -d "${NCBI_SSS_LIBPATH}"  -o  ! -d "${NCBI_SSS_INCLUDE}" ; then
      AC_MSG_RESULT([no])
      NCBI_MISSING_PACKAGE(sss)
   else
      AC_MSG_RESULT([yes])
   fi
fi

if test "$with_sss" = "no" ; then
   NCBI_MISSING_PACKAGE(sssutils)
   NCBI_MISSING_PACKAGE(sssdb)
   NCBI_SSS_INCLUDE=
   NCBI_SSS_LIBPATH=
   LIBSSSUTILS=
   LIBSSSDB=
else
   if test "$with_included_sss" = "yes"; then
      NCBI_SSS_LIBPATH= # Not needed
      ncbi_cv_lib_sssutils=yes
      ncbi_cv_lib_sssdb=yes
      sssutils=sssutils
   else
      NCBI_SSS_LIBPATH="-L${NCBI_SSS_LIBPATH}"
   fi
   NCBI_SSS_INCLUDE="-I${NCBI_SSS_INCLUDE}"

   # SSS UTILS
   if test "$with_sssutils" != "no" ; then
      LIBSSSUTILS="-lsssutils"
      AC_CACHE_CHECK([for the NCBI SSS UTILS library], ncbi_cv_lib_sssutils,
         [CPPFLAGS="$NCBI_SSS_INCLUDE $SYBASE_INCLUDE $orig_CPPFLAGS"
          LIBS="$NCBI_SSS_LIBPATH $LIBSSSUTILS $SYBASE_LIBS $NETWORK_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
             [[@%:@include <hashtab.hpp>]],
             [[ (new C_HashTab(123))->Clear(); ]])],
             [ncbi_cv_lib_sssutils=yes], [ncbi_cv_lib_sssutils=no])])
      if test "$ncbi_cv_lib_sssutils" = yes; then
         AC_DEFINE(HAVE_LIBSSSUTILS, 1,
                   [Define to 1 if the NCBI SSS UTILS library is available.])
         NCBI_PACKAGE(SSSUTILS)
         if test -f "$local_sss/../ncbils2/asn/login.asn" \
           -a -n "$GCRYPT_LIBS"; then
            if test "$with_included_sss" = yes  || \
               grep vformat $NCBI_SSS_INCLUDE/String.hpp >/dev/null 2>&1; then
               NCBI_PACKAGE(LocalNCBILS) # temporary compatibility measure
               NCBI_PACKAGE(NCBILS2)
            fi
         fi
      else
         NCBI_MISSING_PACKAGE(sssutils)
         NCBI_MISSING_PACKAGE(sss)
         LIBSSSUTILS=""
      fi
   fi

   # SSS DB
   if test "$with_sssdb" != "no" ; then
      if test "$with_mt" = "yes" ; then
         LIBSSSDB="-lsssdb -lssssys"
      else
         LIBSSSDB="-lsssdb"
      fi
      AC_CACHE_CHECK([for the NCBI SSS DB library], ncbi_cv_lib_sssdb,
         [CPPFLAGS="$NCBI_SSS_INCLUDE $SYBASE_INCLUDE $orig_CPPFLAGS"
          LIBS="$NCBI_SSS_LIBPATH $LIBSSSDB $SYBASE_LIBS $NETWORK_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
             [[@%:@include <cslink.hpp>]],
             [[ (new CSLink)->connect2server("srv", "user", "pwd", "db"); ]])],
             [ncbi_cv_lib_sssdb=yes], [ncbi_cv_lib_sssdb=no])])
      if test "$ncbi_cv_lib_sssdb" = "yes"; then
         AC_DEFINE(HAVE_LIBSSSDB, 1,
                   [Define to 1 if the NCBI SSS DB library is available.])
         NCBI_PACKAGE(SSSDB)
      else
         NCBI_MISSING_PACKAGE(sssdb)
         NCBI_MISSING_PACKAGE(sss)
         LIBSSSDB=""
      fi
   fi
fi


# SP
if test "$with_sp" != "no" ; then
   if test -n "$SP_INCLUDE"; then
      SP_GENERIC="$SP_INCLUDE/../generic"
   else
      SP_INCLUDE="$SP_PATH/include"
      SP_GENERIC="$SP_PATH/generic"
   fi
   if test -z "$SP_LIBPATH" ; then
      SP_LIBPATH="${SP_PATH}/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}"
   fi
   AC_MSG_CHECKING([for SP directories${SP_PATH:+ in $SP_PATH}])
   if test ! -d "${SP_LIBPATH}"  -o  ! -d "${SP_INCLUDE}" ; then
      AC_MSG_RESULT([no])
      NCBI_MISSING_PACKAGE(sp)
   else
      AC_MSG_RESULT([yes])
   fi
fi

if test "$with_sp" != "no" ; then
   if test -d "$SP_GENERIC"; then
      SP_INCLUDE="-I${SP_INCLUDE} -I${SP_GENERIC}"
   else
      SP_INCLUDE="-I${SP_INCLUDE}"
   fi
   SP_LIBS="-L$SP_LIBPATH -lsp"
   AC_CACHE_CHECK([for the SP SGML library], ncbi_cv_lib_sp,
      [CPPFLAGS="$SP_INCLUDE $orig_CPPFLAGS"
       LIBS="$SP_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <SGMLApplication.h>]],
          [[ SP_API::SGMLApplication app; ]])],
          [ncbi_cv_lib_sp=yes], [ncbi_cv_lib_sp=no])])
   if test "$ncbi_cv_lib_sp" = "no"; then
      NCBI_MISSING_PACKAGE(sp)
   fi
fi

if test "$with_sp" = "no" ; then
   SP_INCLUDE=
   SP_LIBS=
else
   NCBI_PACKAGE(SP)
   AC_DEFINE(HAVE_LIBSP, 1, [Define to 1 if the SP SGML library is available.])
fi


## ORBacus CORBA
if test "$with_orbacus" != no; then
   if test "$with_orbacus" != yes; then
       ORBACUS_PATH=$with_orbacus
   fi
   if test -d "$ORBACUS_PATH"; then
      NCBI_FIX_DIR(ORBACUS_PATH)
   fi
   fullpath=${ORBACUS_PATH}/${DEBUG_SFX}${mt_sfx}${bit64_sfx}
   if test -f ${fullpath}/inc/OB/Config.h ; then
      : ${ORBACUS_INCLUDE="-I$ORBACUS_PATH/include -I$fullpath/inc"}
      NCBI_RPATHIFY_COND(ORBACUS_LIBPATH, $fullpath/lib)
   elif test -f ${ORBACUS_PATH}/include/OB/Config.h ; then
     : ${ORBACUS_INCLUDE="-I$ORBACUS_PATH/include"}
     NCBI_RPATHIFY_COND(ORBACUS_LIBPATH, $ORBACUS_PATH/lib)
   fi
   case "$host_os:$with_mt" in
       linux*:no) LIBJTC="-lJTC -pthread" ;;
       *)         LIBJTC="-lJTC"          ;;
   esac

   case "$with_mt:$ORBACUS_LIBPATH" in
      yes:* | *:-L*MT/lib* )
         LIBOB="-lOB $LIBJTC"
         LIBIMR="-lIMR"
         ;;
      * )
         LIBOB="-lOB"
         LIBIMR=
         ;;
   esac
   AC_CACHE_CHECK([for ORBacus${ORBACUS_PATH:+ in $ORBACUS_PATH}],
      ncbi_cv_lib_orbacus,
      [CPPFLAGS="$ORBACUS_INCLUDE $orig_CPPFLAGS"
       LIBS="$ORBACUS_LIBPATH $LIBOB $NETWORK_LIBS $orig_LIBS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM(
          [[@%:@include <OB/CORBA.h>]],
          [[
            int c = 0;
            char* v[] = { NULL };
            CORBA::ORB_var orb = CORBA::ORB_init(c, v);
            if (!CORBA::is_nil(orb)) orb->destroy();
          ]])],
          [ncbi_cv_lib_orbacus=yes], [ncbi_cv_lib_orbacus=no])])
   if test "$ncbi_cv_lib_orbacus" = "no"; then
      NCBI_MISSING_PACKAGE(orbacus)
   fi
fi
if test "$with_orbacus" = no; then
   ORBACUS_PATH=No_ORBacus
   ORBACUS_INCLUDE=
   ORBACUS_LIBPATH=
   LIBOB=
   LIBIMR=
else
   NCBI_PACKAGE(ORBacus)
   AC_DEFINE(HAVE_ORBACUS, 1,
             [Define to 1 if the ORBacus CORBA package is available.])
fi


## International Components for Unicode (ICU)
if test -z "$ICU_PATH"  &&  icu-config --version >/dev/null 2>&1; then
    ICU_PATH=`icu-config --prefix`
fi

if test "$with_icu" != "no" ; then
   case "$with_icu" in
      yes | "" ) ;;
      *        ) ICU_PATH=$with_icu ;;
   esac
   if test -d "$ICU_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}/lib" \
        -a -z "$ICU_ARCH_PATH"; then
      ICU_ARCH_PATH="$ICU_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}"
   elif test -d "$ICU_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}/lib" \
        -a -z "$ICU_ARCH_PATH"; then
      ICU_ARCH_PATH="$ICU_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}"
   else
      ICU_ARCH_PATH="$ICU_PATH"
   fi
   ICU_BINPATH=${ICU_BINPATH:="$ICU_ARCH_PATH/bin"}
   ICU_LIBPATH=${ICU_LIBPATH:="$ICU_ARCH_PATH/lib"}
   ICU_INCLUDE=
   AC_CACHE_CHECK([for ICU${ICU_ARCH_PATH:+ in $ICU_ARCH_PATH}],
      ncbi_cv_lib_icu,
      [ICU_CONFIG=`$ICU_BINPATH/icu-config --bindir 2>/dev/null`/icu-config
       if test -x "$ICU_CONFIG" ; then
          ICU_INCLUDE=`$ICU_CONFIG --cppflags-searchpath`
          NCBI_RPATHIFY_OUTPUT(ICU_LIBS, $ICU_CONFIG --ldflags-searchpath)
          ICU_LIBS="$ICU_LIBS `$ICU_CONFIG --ldflags-libsonly`"

          CPPFLAGS="$ICU_INCLUDE $orig_CPPFLAGS"
          LIBS="$ICU_LIBS $orig_LIBS"
          AC_LINK_IFELSE([AC_LANG_PROGRAM(
            [[@%:@include <unicode/unistr.h>]],
            [[int32_t i = UNICODE_STRING_SIMPLE("foo").indexOf('f');]])],
            [ncbi_cv_lib_icu=yes], [ncbi_cv_lib_icu=no])
       else
          ncbi_cv_lib_icu=no
       fi])
   if test "$ncbi_cv_lib_icu" = "no"; then
      NCBI_MISSING_PACKAGE(icu)
   fi
fi

if test "$with_icu" = "no" ; then
   ICU_PATH="No_ICU"
   ICU_INCLUDE=
   ICU_LIBS=
   ICU_STATIC_LIBS=
else
   NCBI_PACKAGE(ICU)
   ICU_CONFIG="`$ICU_BINPATH/icu-config --bindir`/icu-config"
   # The "yes" may have been cached; get the actual settings again if needed
   if test -z "$ICU_INCLUDE"; then
      ICU_INCLUDE=`$ICU_CONFIG --cppflags-searchpath`
      NCBI_RPATHIFY_OUTPUT(ICU_LIBS, $ICU_CONFIG --ldflags-searchpath)
      ICU_LIBS="$ICU_LIBS `$ICU_CONFIG --ldflags-libsonly`"
   fi
   ICU_SEARCHPATH=`$ICU_CONFIG --ldflags-searchpath | sed -e "$no_usr_lib"`
   ICU_STATIC_LIBS=`$ICU_CONFIG --ldflags-libsonly | sed -e 's/-licu/-lsicu/g'`
   ICU_STATIC_LIBS="$ICU_SEARCHPATH $ICU_STATIC_LIBS"
   AC_DEFINE(HAVE_ICU, 1, [Define to 1 if ICU libraries are available.])
fi


### XML/XSL libraries
NCBI_CHECK_THIRD_PARTY_LIB(expat,
 [AC_LANG_PROGRAM([@%:@include <expat.h>],
    [XML_Parser parser = XML_ParserCreate("utf-8");])])
if test -f "${EXPAT_PATH}/lib${bit64_sfx}/libexpat-static.a"; then
   EXPAT_STATIC_LIBS="-L${EXPAT_PATH}/lib${bit64_sfx} -lexpat-static"
else
   EXPAT_STATIC_LIBS=${EXPAT_LIBS}
fi

case "$with_sablot" in
   no       ) ;;
   yes | "" ) ;;
   *        ) SABLOT_PATH=$with_sablot ;;
esac
vpath="$SABLOT_PATH/${compiler_vpfx}build"
test -d "$vpath"  &&  SABLOT_PATH=$vpath
if test -d "$SABLOT_PATH"; then
   NCBI_FIX_DIR(SABLOT_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(sablot,
 [AC_LANG_PROGRAM([@%:@include <sablot.h>],
    [SDOM_Document* D; int x = SablotParse(NULL, "file:/dev/null", D);])],
 $EXPAT_LIBS)
if test -f "${SABLOT_PATH}/lib${bit64_sfx}/libsablot-static.a"; then
   SABLOT_STATIC_LIBS="-L${SABLOT_PATH}/lib${bit64_sfx} -lsablot-static $EXPAT_STATIC_LIBS"
else
   SABLOT_STATIC_LIBS=${SABLOT_LIBS}
fi

# test -d "$LIBXML_PATH" || LIBXML_PATH=`xml2-config --prefix 2>/dev/null`
if test "$with_libxml" != "no"; then
   case "$with_libxml" in
      yes | "" ) ;;
      *        ) LIBXML_PATH=$with_libxml ;;
   esac
   for pfx in "$compiler_vpfx" "$compiler_pfx" "" ; do
      vpath=$LIBXML_PATH/$pfx${DEBUG_SFX}${mt_sfx}${bit64_sfx}
      if test -d "$vpath" ; then
         LIBXML_PATH=$vpath
         break
      fi
   done
   if test -d "$LIBXML_PATH"; then
      NCBI_FIX_DIR(LIBXML_PATH)
      in_path=" in $LIBXML_PATH"
      if test -n "$LIBXML_INCLUDE"; then
         :
      elif test -d "$LIBXML_PATH/include/libxml2/libxml"; then
         LIBXML_INCLUDE="-I$LIBXML_PATH/include/libxml2 -I$LIBXML_PATH/include"
      elif test -d "$LIBXML_PATH/include/libxml"; then
         LIBXML_INCLUDE="-I$LIBXML_PATH/include";
      else
         case "$host_os" in
            darwin* )
               LIBXML_INCLUDE="-iwithsysroot $LIBXML_PATH/include/libxml2"
               ;;
         esac
      fi
      if test -d "$LIBXML_PATH/lib${bit64_sfx}"; then
         LIBXML_LIBPATH_="$LIBXML_PATH/lib${bit64_sfx}"
      elif test -d "$LIBXML_PATH/lib"; then
         LIBXML_LIBPATH_="$LIBXML_PATH/lib"
      fi
      NCBI_RPATHIFY_COND(LIBXML_LIBPATH, $LIBXML_LIBPATH_)
      LIBXML_LIBS="$LIBXML_LIBPATH -lxml2"
   else
      case "$host_os" in
         darwin* ) LIBXML_INCLUDE="-iwithsysroot /usr/include/libxml2" ;;
         *       ) LIBXML_INCLUDE="-I/usr/include/libxml2" ;;
      esac
      LIBXML_LIBS="-lxml2"
      in_path=
   fi
   LIBXML_LIBS="$LIBXML_LIBS $ICONV_LIBS"
   AC_CACHE_CHECK([for libxml2$in_path], ncbi_cv_lib_libxml,
      CPPFLAGS="$LIBXML_INCLUDE $orig_CPPFLAGS"
      LIBS="$LIBXML_LIBS $orig_LIBS"
      [AC_LINK_IFELSE(
         [AC_LANG_PROGRAM(
             [@%:@include <libxml/parser.h>],
             [xmlDocPtr doc = xmlParseFile("foo.xml");])],
      [ncbi_cv_lib_libxml=yes], [ncbi_cv_lib_libxml=no])])
   if test "$ncbi_cv_lib_libxml" = "no"; then
      NCBI_MISSING_PACKAGE(libxml)
   fi
fi
if test "$with_libxml" = "no"; then
   LIBXML_PATH="No_LIBXML"
   LIBXML_INCLUDE=
   LIBXML_LIBPATH_=
   LIBXML_LIBS=
else
   NCBI_PACKAGE(LIBXML)
   LIBXML_INCLUDE="$LIBXML_INCLUDE"
   AC_DEFINE(HAVE_LIBXML, 1, [Define to 1 if libxml2 is available.])
   export LIBXML_LIBPATH
fi
AC_SUBST(LIBXML_INCLUDE)
AC_SUBST(LIBXML_LIBS)

if test -f "${LIBXML_LIBPATH_}/libxml2-static.a"; then
   LIBXML_STATIC_LIBS="-L${LIBXML_LIBPATH_} -lxml2-static $ICONV_LIBS"
   if test "x$with_bin_release" = "xyes"; then
      LIBXML_LIBS=$LIBXML_STATIC_LIBS
   fi
else
   LIBXML_STATIC_LIBS=${LIBXML_LIBS}
fi

: ${LIBXSLT_PATH=$LIBXML_PATH}
NCBI_CHECK_THIRD_PARTY_LIB_EX(libxslt, LIBXSLT, xslt,
 [AC_LANG_PROGRAM([@%:@include <libxslt/xslt.h>], [xsltInit()])],
 [], [$LIBXML_LIBS $Z_LIBS], [$LIBXML_INCLUDE])

# XXX - they might be in different directories in some setups
if test -f "${LIBXML_LIBPATH_}/libxslt-static.a"; then
   LIBXSLT_STATIC_LIBS="-L${LIBXML_LIBPATH_} -lxslt-static"
   if test "x$with_bin_release" = "xyes"; then
      LIBXSLT_LIBS=$LIBXSLT_STATIC_LIBS
   fi
else
   LIBXSLT_STATIC_LIBS=${LIBXSLT_LIBS}
fi

AC_PATH_PROG(XSLTPROC, xsltproc, :,
   [$LIBXSLT_PATH/bin:`dirname $LIBXML_LIBPATH_ 2>/dev/null`/bin:$PATH])

: ${LIBEXSLT_PATH=$LIBXSLT_PATH}
if env PKG_CONFIG_PATH=$LIBEXSLT_PATH/lib/pkgconfig pkg-config libexslt --libs \
    2>/dev/null | $EGREP_Q gcrypt; then
   exslt_autodep=$GCRYPT_LIBS
else
   exslt_autodep=
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(libexslt, LIBEXSLT, exslt,
 [AC_LANG_PROGRAM([@%:@include <libexslt/exslt.h>], [exsltRegisterAll()])],
 [$exslt_autodep], [$LIBXSLT_LIBS $LIBXML_LIBS $Z_LIBS], [$LIBXSLT_INCLUDE])

# XXX - they might be in different directories in some setups
if test -f "${LIBXML_LIBPATH_}/libexslt-static.a"; then
   LIBEXSLT_STATIC_LIBS="-L${LIBXML_LIBPATH_} -lexslt-static $GCRYPT_LIBS"
   if test "x$with_bin_release" = "xyes"; then
      LIBEXSLT_LIBS=$LIBEXSLT_STATIC_LIBS
   fi
else
   LIBEXSLT_STATIC_LIBS=${LIBEXSLT_LIBS}
fi

if test "$with_xerces" != no; then
   if test "${with_xerces-yes}" != yes; then
      XERCES_PATH=$with_xerces
   fi
   if test -d "$XERCES_PATH"; then
      NCBI_FIX_DIR(XERCES_PATH)
   fi
   vpath="$XERCES_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}"
   if test -d "$vpath/lib"; then
      XERCES_PATH=$vpath
      NCBI_FIX_DIR(XERCES_PATH)
   elif test -d "$vpath"; then
      : ${XERCES_LIBPATH=$vpath}
      NCBI_FIX_DIR(XERCES_LIBPATH)
   else
      vpath="$XERCES_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}"
      if test -d "$vpath/lib"; then
         XERCES_PATH=$vpath
         NCBI_FIX_DIR(XERCES_PATH)
      elif test -d "$vpath"; then
         XERCES_LIBPATH=$vpath
         NCBI_FIX_DIR(XERCES_LIBPATH)
      fi
   fi
   if test -d "$XERCES_PATH"; then
      in_path=" in $XERCES_PATH"
      : ${XERCES_INCLUDE=-I$XERCES_PATH/include}
      : ${XERCES_LIBPATH=$XERCES_PATH/lib}
   else
      in_path=''
   fi
   NCBI_RPATHIFY(XERCES_LIBPATH_, $XERCES_LIBPATH)
   XERCES_LIBS="$XERCES_LIBPATH_ -lxerces-c"
   AC_CACHE_CHECK([for Xerces-C++$in_path], ncbi_cv_lib_xerces_c,
      [CPPFLAGS="$XERCES_INCLUDE $orig_CPPFLAGS"
       LIBS="$XERCES_LIBS $ICU_LIBS $orig_LIBS"
       AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <xercesc/dom/DOM.hpp>]],
             [[xercesc::DOMImplementation* impl
               = xercesc::DOMImplementationRegistry::getDOMImplementation
                 (xercesc::XMLString::transcode("XML 1.0"));]])],
          ncbi_cv_lib_xerces_c=yes, ncbi_cv_lib_xerces_c=no)])
   if test $ncbi_cv_lib_xerces_c = yes; then
      if test -f "$XERCES_LIBPATH/libxerces-c-static.a"; then
         XERCES_STATIC_LIBS="-L$XERCES_LIBPATH -lxerces-c-static $CURL_LIBS"
      else
         XERCES_STATIC_LIBS=$XERCES_LIBS
      fi
   else
      NCBI_MISSING_PACKAGE(xerces)
   fi
fi
if test "$with_xerces" != no; then
   NCBI_PACKAGE(Xerces)
   AC_DEFINE(HAVE_XERCES, 1, [Define to 1 if Xerces-C++ is available.])
else
   XERCES_INCLUDE=
   XERCES_LIBS=
   XERCES_STATIC_LIBS=
fi

if test "$with_xalan" != no; then
   if test "${with_xalan-yes}" != yes; then
      XALAN_PATH=$with_xalan
   fi
   if test -d "$XALAN_PATH"; then
      NCBI_FIX_DIR(XALAN_PATH)
   fi
   vpath="$XALAN_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}"
   if test -d "$vpath/lib"; then
      XALAN_PATH=$vpath
      NCBI_FIX_DIR(XALAN_PATH)
   elif test -d "$vpath"; then
      : ${XALAN_LIBPATH=$vpath}
      NCBI_FIX_DIR(XALAN_LIBPATH)
   else
      vpath="$XALAN_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}${mt_sfx}"
      if test -d "$vpath/lib"; then
         XALAN_PATH=$vpath
         NCBI_FIX_DIR(XALAN_PATH)
      elif test -d "$vpath"; then
         XALAN_LIBPATH=$vpath
         NCBI_FIX_DIR(XALAN_LIBPATH)
      fi
   fi
   if test -d "$XALAN_PATH"; then
      in_path=" in $XALAN_PATH"
      : ${XALAN_INCLUDE=-I$XALAN_PATH/include}
      : ${XALAN_LIBPATH=$XALAN_PATH/lib}
   else
      in_path=''
   fi
   NCBI_RPATHIFY(XALAN_LIBPATH_, $XALAN_LIBPATH)
   XALAN_LIBS="$XALAN_LIBPATH_ -lxalan-c -lxalanMsg"
   AC_CACHE_CHECK([for Xalan-C++$in_path], ncbi_cv_lib_xalan_c,
      [CPPFLAGS="$XALAN_INCLUDE $XERCES_INCLUDE $orig_CPPFLAGS"
       LIBS="$XALAN_LIBS $XERCES_LIBS $ICU_LIBS $orig_LIBS"
       AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <xalanc/XalanTransformer/XalanTransformer.hpp>]],
             [[xalanc::XalanTransformer::initialize();]])],
          ncbi_cv_lib_xalan_c=yes, ncbi_cv_lib_xalan_c=no)])
   if test $ncbi_cv_lib_xalan_c = yes; then
      if test -f "$XALAN_LIBPATH/libxalan-c-static.a"; then
         XALAN_STATIC_LIBS="-L$XALAN_LIBPATH -lxalan-c-static -lxalanMsg-static"
      else
         XALAN_STATIC_LIBS=$XALAN_LIBS
      fi
   else
      NCBI_MISSING_PACKAGE(xalan)
   fi
fi
if test "$with_xalan" != no; then
   NCBI_PACKAGE(Xalan)
   AC_DEFINE(HAVE_XALAN, 1, [Define to 1 if Xalan-C++ is available.])
else
   XALAN_INCLUDE=
   XALAN_LIBS=
   XALAN_STATIC_LIBS=
fi

if test "$with_zorba" != no; then
   if test "${with_zorba-yes}" != yes; then
      ZORBA_PATH=$with_zorba
   fi
   if test -d "$ZORBA_PATH"; then
      NCBI_FIX_DIR(ZORBA_PATH)
   fi
   vpath="$ZORBA_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}"
   if test -d "$vpath/lib"; then
      ZORBA_PATH=$vpath
      NCBI_FIX_DIR(ZORBA_PATH)
   elif test -d "$vpath"; then
      : ${ZORBA_LIBPATH=$vpath}
      NCBI_FIX_DIR(ZORBA_LIBPATH)
   else
      vpath="$ZORBA_PATH/${compiler_pfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}"
      if test -d "$vpath/lib"; then
         ZORBA_PATH=$vpath
         NCBI_FIX_DIR(ZORBA_PATH)
      elif test -d "$vpath"; then
         ZORBA_LIBPATH=$vpath
         NCBI_FIX_DIR(ZORBA_LIBPATH)
      fi
   fi
   ZORBA_CONFIG="$ZORBA_PATH/bin/zorba-config"
   if test -x "$ZORBA_CONFIG"; then
      ZORBA_PATH=`$ZORBA_CONFIG --prefix`
      : ${ZORBA_INCLUDE=`$ZORBA_CONFIG --cppflags`}
   fi
   if test -d "$ZORBA_PATH"; then
      in_path=" in $ZORBA_PATH"
      : ${ZORBA_INCLUDE=-I$ZORBA_PATH/include}
      : ${ZORBA_LIBPATH=$ZORBA_PATH/lib}
   else
      in_path=''
   fi
   if test -x "$ZORBA_CONFIG"; then
      ZORBA_LIBS=`$ZORBA_CONFIG --libs`
   else
      NCBI_RPATHIFY(ZORBA_LIBPATH_, $ZORBA_LIBPATH)
      ZORBA_LIBS="$ZORBA_LIBPATH_ -lzorba_simplestore"
   fi
   AC_CACHE_CHECK([for Zorba$in_path], ncbi_cv_lib_zorba,
      [CPPFLAGS="$ZORBA_INCLUDE $orig_CPPFLAGS"
       LIBS="$ZORBA_LIBS $orig_LIBS"
       AC_LINK_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <zorba/zorba.h>]],
             [[zorba::Version v = zorba::Zorba::version();]])],
          ncbi_cv_lib_zorba=yes, ncbi_cv_lib_zorba=no)])
   if test $ncbi_cv_lib_zorba = yes; then
      if test -x "$ZORBA_CONFIG"; then
         ZORBA_STATIC_LIBS=`$ZORBA_CONFIG --static-libs`
      elif test -f "$ZORBA_LIBPATH/libzorba_simplestore-static.a"; then
         ZORBA_STATIC_LIBS="-L$ZORBA_LIBPATH -lzorba_simplestore-static $XERCES_STATIC_LIBS $ICU_STATIC_LIBS $LIBXSLT_STATIC_LIBS $LIBXML_STATIC_LIBS"
      else
         ZORBA_STATIC_LIBS=$ZORBA_LIBS
      fi
   else
      NCBI_MISSING_PACKAGE(zorba)
   fi
fi
if test "$with_zorba" != no; then
   NCBI_PACKAGE(Zorba)
   AC_DEFINE(HAVE_ZORBA, 1, [Define to 1 if Zorba is available.])
else
   ZORBA_INCLUDE=
   ZORBA_LIBS=
   ZORBA_STATIC_LIBS=
fi

### SQLite
case "$with_sqlite3" in
   yes | '' ) ;;
   *        ) SQLITE3_PATH=$with_sqlite3 ;;
esac

if test -d "$SQLITE3_PATH"; then
   NCBI_FIX_DIR(SQLITE3_PATH)
fi
if test -d "$SQLITE3_PATH/${compiler_pfx}${DEBUG_SFX}${MT_SFX}${bit64_sfx}/lib"; then
   SQLITE3_LIBDIR=$SQLITE3_PATH/${compiler_pfx}${DEBUG_SFX}${MT_SFX}${bit64_sfx}/lib
elif test -d $SQLITE3_PATH/lib${bit64_sfx}; then
   SQLITE3_LIBDIR=$SQLITE3_PATH/lib${bit64_sfx}
else
   SQLITE3_LIBDIR=$SQLITE3_PATH/lib
fi
NCBI_RPATHIFY(SQLITE3_LIBPATH, $SQLITE3_LIBDIR)
NCBI_CHECK_THIRD_PARTY_LIB(sqlite3,
 [AC_LANG_PROGRAM([@%:@include <sqlite3.h>],
    [sqlite3_pcache_methods m;
     int status = sqlite3_config(SQLITE_CONFIG_GETPCACHE, &m);])])
if test -n "$SQLITE3_LIBS"; then
   CPPFLAGS="$SQLITE3_INCLUDE $orig_CPPFLAGS"
   AC_CHECK_HEADER(sqlite3async.h,
      [AC_DEFINE(HAVE_SQLITE3ASYNC_H, 1,
          [Define to 1 if you have the <sqlite3async.h> header file.])
       NCBI_PACKAGE(SQLITE3ASYNC)])
   LIBS="$SQLITE3_LIBS $orig_LIBS"
   AC_CHECK_FUNCS(sqlite3_unlock_notify)
   SQLITE3_WRAPPER=sqlitewrapp
else
   SQLITE3_WRAPPER=
fi
if test -n "$SQLITE3_LIBS" -a -f "$SQLITE3_LIBDIR/libsqlite3-static.a"; then
   SQLITE3_STATIC_LIBS="-L$SQLITE3_LIBDIR -lsqlite3-static"
   if test "x$with_bin_release" = "xyes"; then
      SQLITE3_LIBS=$SQLITE3_STATIC_LIBS
   fi
else
   SQLITE3_STATIC_LIBS=$SQLITE3_LIBS
fi


# NCBI SRA/VDB
VDB_POST_LINK=:
VDB_REQ=VDB
if test "$with_vdb" != "no" ; then
   # CURL?
   vdb_deps="$NETWORK_LIBS $BZ2_LIBS $Z_LIBS $DL_LIBS"
   # In MT builds, ORIG_LIBS already contains THREAD_LIBS.  However,
   # VDB is always threaded, and may need explicit THREAD_LIBS when
   # used statically.
   if test "$with_mt" = no; then
      vdb_deps="$vdb_deps $THREAD_LIBS"
   fi
   vdb_static_deps="$LIBXML_STATIC_LIBS $vdb_deps"
   vdb_deps="$LIBXML_LIBS $vdb_deps"
   if test "${with_vdb:-yes}" != "yes" -a -d "$with_vdb"; then
      VDB_PATH=$with_vdb
   fi
   if test -d "$VDB_PATH"; then
      : ${with_downloaded_vdb=no}
   else
      : ${with_downloaded_vdb=$with_vdb}
   fi
   if test "$with_downloaded_vdb" != "no"; then
      AC_MSG_NOTICE([trying to build the NCBI SRA/VDB Toolkit from GitHub.])
      VDB_PATH=`$real_srcdir/scripts/common/add_vdb.sh 2>&AS_MESSAGE_LOG_FD`
      status=$?
      if test $status != 0; then
         message="SRA/VDB build failed with status $status"
      elif test ! -d "$VDB_PATH"; then
         message="SRA/VDB build nominally succeeded, but failed to report where"
      else
         message=
      fi
      case "$message:$with_downloaded_vdb" in
         :*    ) ;;
         *:yes ) AC_MSG_FAILURE([$message]) ;;
         *     ) AC_MSG_WARN([$message])  ;;
      esac
   fi
   # if test "$with_included_vdb" != "yes"; then
      if test -z "$VDB_PATH"; then
         in_path=
      else
         dnl NCBI_FIX_DIR(VDB_PATH)
         vdb_parent=`dirname "$VDB_PATH"`
         NCBI_FIX_DIR(vdb_parent)
         VDB_PATH=$vdb_parent/`basename "$VDB_PATH"`
         in_path=" in $VDB_PATH"
         case "$host_os" in
            darwin*  ) vdb_os=mac ;;
            linux*   ) vdb_os=linux ;;
            solaris* ) vdb_os=sun ;;
         esac
         case "$VDB_PATH" in
            */cxx_toolkit/* ) vdb_os_interfaces=$vdb_os/../interfaces ;;
            *               ) vdb_os_interfaces= ;;
         esac
         for x in $vdb_os_interfaces interfaces include; do
            if test -d "$VDB_PATH/$x"; then
               vdb_inc_root=$VDB_PATH/$x
               : ${VDB_INCLUDE="-I$vdb_inc_root"}
               break
            fi
         done
         vdb_inc_subdirs=cc/gcc
         case "$host_cpu:$bit64_sfx" in
            a*r*:*  ) vdb_inc_subdirs="cc/gcc/arm64 $vdb_inc_subdirs" ;;
            *86*:64 ) vdb_inc_subdirs="cc/gcc/x86_64 $vdb_inc_subdirs" ;;
            *86*:*  ) vdb_inc_subdirs="cc/gcc/fat86 $vdb_inc_subdirs" ;;
         esac
         case "$ncbi_compiler" in
            *CLANG ) vdb_inc_subdirs="cc/clang $vdb_inc_subdirs" ;;
            ICC    ) vdb_inc_subdirs="cc/icc $vdb_inc_subdirs"   ;;
         esac
         vdb_inc_subdirs="os/$vdb_os os/unix $vdb_inc_subdirs"
         for x in $vdb_inc_subdirs; do
            VDB_INCLUDE="$VDB_INCLUDE -I$vdb_inc_root/$x"
         done
         case "$DEBUG_SFX" in
            Debug )
               VDB_INCLUDE="$VDB_INCLUDE -D_DEBUGGING"
               vdb_mode=debug
               ;;
            Release )
               vdb_mode=release
               ;;
         esac
         case "$host_os:$host_cpu:$bit64_sfx" in
            darwin*:*86*:64 ) vdb_libpath=mac/$vdb_mode/x86_64/lib   ;;
            darwin*:*86*:* )  vdb_libpath=mac/$vdb_mode/fat86/lib    ;;
            darwin*:arm*   )  vdb_libpath=mac/$vdb_mode/aarch64/lib  ;;
            linux*:*86*:64 )  vdb_libpath=linux/$vdb_mode/x86_64/lib ;;
            linux*:aarch64* ) vdb_libpath=linux/$vdb_mode/aarch64/lib ;;
            * )
               if test -n "$with_vdb"; then
                  AC_MSG_ERROR([--with-vdb explicitly specified,
                                but not supported on this platform.])
               fi
               ;;
         esac
         for x in "$vdb_libpath" "lib${bit64_sfx:-32}" lib; do
            if test -n "$x" -a -d "$VDB_PATH/$x"; then
               : ${VDB_LIBDIR=$VDB_PATH/$x}
               break
            fi
         done
      fi
      NCBI_RPATHIFY_COND(VDB_LIBS, $VDB_LIBDIR, [ -lncbi-vdb $vdb_deps])
      CPPFLAGS="$orig_CPPFLAGS $VDB_INCLUDE"
      LIBS="$orig_LIBS $VDB_LIBS"
      AC_CACHE_CHECK([for ncbi-vdb$in_path], ncbi_cv_lib_ncbi_vdb,
         AC_LINK_IFELSE([
            AC_LANG_PROGRAM([@%:@include <sra/sradb.h>],
               [const SRAMgr* mgr; SRAMgrMakeRead(&mgr);])],
            [ncbi_cv_lib_ncbi_vdb=yes], [ncbi_cv_lib_ncbi_vdb=no]))
      if test "$ncbi_cv_lib_ncbi_vdb" = yes; then
         NCBI_PACKAGE(VDB)
         if test -f "$VDB_LIBDIR/libncbi-vdb-static.a"; then
            VDB_STATIC_LIBS="-L$VDB_LIBDIR -lncbi-vdb-static $vdb_static_deps"
            if test "$with_static_vdb" = yes; then
               VDB_LIBS="-L$VDB_LIBDIR -lncbi-vdb-static $vdb_deps"
            fi
         else
            VDB_STATIC_LIBS=$VDB_LIBS
         fi
         case "$host_os" in
            darwin*)
               inst_name=`otool -D $VDB_LIBDIR/libncbi-vdb.dylib 2>/dev/null \
                          | grep -v ':$'`
               case "$inst_name" in
                   @executable_path* )
                      major=`echo $inst_name | sed -ne 's,.*/libncbi-vdb\.\([[1-9]][[0-9]]*\).*\.dylib$,\1,p'`
                      test -z "$major"  || \
                         VDB_POST_LINK="install_name_tool -change $inst_name @rpath/libncbi-vdb.$major.dylib"
                      ;;
               esac
               ;;
         esac
         AC_DEFINE(HAVE_NCBI_VDB, 1,
            [Define to 1 if you have NCBI's SRA/VDB SDK/Toolkit.])
         bamread=bamread
         sraread=sraread
         ncbi_id2proc_snp=ncbi_id2proc_snp
         ncbi_id2proc_wgs=ncbi_id2proc_wgs
         ncbi_xloader_bam=ncbi_xloader_bam
         ncbi_xloader_csra=ncbi_xloader_csra
         ncbi_xloader_snp=ncbi_xloader_snp
         ncbi_xloader_sra=ncbi_xloader_sra
         ncbi_xloader_vdbgraph=ncbi_xloader_vdbgraph
         ncbi_xloader_wgs=ncbi_xloader_wgs
      else
         VDB_INCLUDE=
         VDB_LIBS=
         VDB_STATIC_LIBS=
         bamread=
         sraread=
         ncbi_id2proc_snp=
         ncbi_id2proc_wgs=
         ncbi_xloader_bam=
         ncbi_xloader_csra=
         ncbi_xloader_snp=
         ncbi_xloader_sra=
         ncbi_xloader_vdbgraph=
         ncbi_xloader_wgs=
      fi
   # else ...
   # fi
   if test -z "$VDB_LIBS"; then
      NCBI_MISSING_PACKAGE(vdb)
      NCBI_MISSING_PACKAGE(ngs)
   fi
else
   NCBI_MISSING_PACKAGE(ngs)
fi


### NCBI NGS SDK
if test "$with_ngs" != "no" ; then
   if test "${with_ngs:-yes}" != "yes" -a -d "$with_ngs"; then
      NGS_PATH=$with_ngs
   fi
   NGS_INCLUDE="-I$NGS_PATH/include"
   case "$host_cpu:$bit64_sfx" in
      *86*:64 ) extra_inc="-I$NGS_PATH/include/ngs/unix/x86_64" ;;
      *86*:*  ) extra_inc="-I$NGS_PATH/include/ngs/unix/fat86"  ;;
      *       ) extra_inc=''                                    ;;
   esac
   NGS_INCLUDE="$NGS_INCLUDE $extra_inc"
   CPPFLAGS="$NGS_INCLUDE $VDB_INCLUDE $orig_CPPFLAGS"
   for x in "$vdb_libpath" "lib${bit64_sfx:-32}" lib; do
      if test -n "$x" -a -d "$NGS_PATH/$x"; then
         : ${NGS_LIBDIR=$NGS_PATH/$x}
         break
      fi
   done
   NCBI_RPATHIFY(NGS_LIBPATH, [$NGS_LIBDIR])
   if test -n "$NGS_PATH"; then
      in_path=" in $NGS_PATH"
   else
      in_path=
   fi
   LIBS="$orig_LIBS $NGS_LIBPATH -lncbi-ngs $VDB_LIBS"
   AC_CACHE_CHECK([for libncbi-ngs$in_path], ncbi_cv_lib_ncbi_ngs,
      AC_LINK_IFELSE([
         AC_LANG_PROGRAM([@%:@include <ngs/itf/PileupItf.h>],
            [struct NGS_Pileup_v1_vt * p1vt = &ITF_Pileup_vt;])],
         [ncbi_cv_lib_ncbi_ngs=yes], [ncbi_cv_lib_ncbi_ngs=no]))
   if test $ncbi_cv_lib_ncbi_ngs=yes; then
      NGS_C_LIBS=-lncbi-ngs
   fi
   LIBS=$orig_LIBS
   NCBI_CHECK_THIRD_PARTY_LIB_EX(ngs, NGS, ncbi-ngs-c++,
      [AC_LANG_PROGRAM([[@%:@include <ncbi-vdb/NGS.hpp>]],
           [[ncbi::NGS::setAppVersionString("conftest.0.0.0");
             ngs::ReadCollection coll
             = ncbi::NGS::openReadCollection("foo");]])],
      [-lngs-c++ $NGS_C_LIBS], $VDB_LIBS, $extra_inc)
   if test -n "$NGS_LIBS"; then
      if test -f "$NGS_LIBDIR/libncbi-ngs-c++-static.a"; then
         NGS_STATIC_LIBS="-L$NGS_LIBDIR -lncbi-ngs-c++-static"
         NGS_STATIC_LIBS="$NGS_STATIC_LIBS -lngs-c++-static"
         if test -n "$NGS_C_LIBS"; then
            NGS_STATIC_LIBS="$NGS_STATIC_LIBS $NGS_C_LIBS-static"
         fi
      else
         NGS_STATIC_LIBS=$NGS_LIBS
      fi
   else
      NCBI_MISSING_PACKAGE(ngs)
   fi
fi


### OEChem
# somewhat kludgish, as we now wanto to add in oeiupac and oedepict,
# which depend on oechem....
NCBI_CHECK_THIRD_PARTY_LIB(oechem,
 [AC_LANG_PROGRAM([@%:@include <oechem.h>],
    [OEChem::OEMol mol; OEChem::OEConfBase* c = mol.GetActive();])],
  -loeiupac -loedepict -loechem -loesystem -loeplatform -lz, $NETWORK_LIBS)
if test -n "$OECHEM_LIBS"; then
   OECHEM_LIBS=`echo $OECHEM_LIBS | sed -e 's/-loechem \(.*-loechem .*\)/\1/'`
fi


### Sun/Univa Grid Engine
case "$host:$NCBI_PLATFORM_BITS" in
   i?86-*-darwin*      ) SGE_PLATFORMS='darwin-x86'          ;;
   i?86-*-linux*       ) SGE_PLATFORMS='lx24-x86 lx-x86'     ;;
   i?86-*-solaris*:32  ) SGE_PLATFORMS='sol-x86'             ;;
   i?86-*-solaris*:64  ) SGE_PLATFORMS='sol-amd64'           ;;
   powerpc-*-darwin*   ) SGE_PLATFORMS='darwin-ppc'          ;;
   sparc-*-solaris*:32 ) SGE_PLATFORMS='sol-sparc'           ;;
   sparc-*-solaris*:64 ) SGE_PLATFORMS='sol-sparc64'         ;;
   x86_64-*-linux*     ) SGE_PLATFORMS='lx24-amd64 lx-amd64' ;;
esac

case "$with_sge" in
   yes | "" ) ;;
   *        ) SGE_PATH=$with_sge ;;
esac
if test -d "$SGE_PATH" -a -z "$SGE_LIBPATH"; then
   for x in $SGE_PLATFORMS; do
      if test -d "$SGE_PATH/lib/$x"; then
         SGE_LIBPATH="$SGE_PATH/lib/$x"
         break
      fi
   done
   BASE_SGE_LIBPATH=$SGE_LIBPATH
   NCBI_RPATHIFY(SGE_LIBPATH, $SGE_LIBPATH)
   # Try to use a dedicated directory without alternate versions of
   # system libraries such as OpenSSL.
   if test -d "$BASE_SGE_LIBPATH" -a -d "$SGE_PATH/lib/drmaa"; then
      SGE_LIBPATH=`echo $SGE_LIBPATH \
          | sed -e "s,-L$BASE_SGE_LIBPATH,-L$SGE_PATH/lib/drmaa,g"`
   fi
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(sge, SGE, drmaa,
  [AC_LANG_PROGRAM([[@%:@include <sys/types.h>
                     @%:@include <drmaa.h>]],
     [[char buf[1024]; drmaa_init("SGE", buf, sizeof(buf));]])])


### DRMAA2
: ${DRMAA2_PATH=$SGE_PATH}
case "$with_drmaa2" in
   yes | "" ) ;;
   *        ) DRMAA2_PATH=$with_drmaa2 ;;
esac
if test -d "$DRMAA2_PATH" -a -z "$DRMAA2_LIBPATH"; then
   for x in $SGE_PLATFORMS; do
      if test -d "$DRMAA2_PATH/lib/$x"; then
         DRMAA2_LIBPATH="$DRMAA2_PATH/lib/$x"
         break
      fi
   done
   BASE_DRMAA2_LIBPATH=$DRMAA2_LIBPATH
   NCBI_RPATHIFY(DRMAA2_LIBPATH, $DRMAA2_LIBPATH)
   # Try to use a dedicated directory without alternate versions of
   # system libraries such as OpenSSL.
   if test -d "$BASE_DRMAA2_LIBPATH" -a -d "$DRMAA2_PATH/lib/drmaa"; then
      DRMAA2_LIBPATH=`echo $DRMAA2_LIBPATH \
          | sed -e "s,-L$BASE_DRMAA2_LIBPATH,-L$DRMAA2_PATH/lib/drmaa,g"`
   fi
fi
AC_LANG_PUSH(C)
NCBI_CHECK_THIRD_PARTY_LIB(drmaa2,
  [AC_LANG_PROGRAM([[@%:@include <drmaa2.h>]],
     [[drmaa2_create_rsession("foo", "bar");]])])
AC_LANG_POP(C)


### muParser
case "$with_muparser" in
   yes | '' ) ;;
   *        ) MUPARSER_PATH=$with_muparser ;;
esac

if test -d "$MUPARSER_PATH"; then
   NCBI_FIX_DIR(MUPARSER_PATH)
fi
if test -d "$MUPARSER_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}/lib"; then
   MUPARSER_LIBPATH=-L$MUPARSER_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}/lib
elif test -d "$MUPARSER_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}/lib"; then
   MUPARSER_LIBPATH=-L$MUPARSER_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}/lib
fi

NCBI_CHECK_THIRD_PARTY_LIB(muparser,
  [AC_LANG_PROGRAM([[@%:@include <muParser.h>]],
     [[mu::Parser parser;]])])


### hdf5
case "$with_hdf5" in
   yes | '' ) ;;
   *        ) HDF5_PATH=$with_hdf5 ;;
esac

if test -d "$HDF5_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}"; then
   HDF5_PATH=$HDF5_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}
elif test -d "$HDF5_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}"; then
   HDF5_PATH=$HDF5_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}
fi
if test -d "$HDF5_PATH"; then
   NCBI_FIX_DIR(HDF5_PATH)
fi

NCBI_CHECK_THIRD_PARTY_LIB_EX(hdf5, HDF5, hdf5_cpp,
  [AC_LANG_PROGRAM([[@%:@include <H5Cpp.h>]],
     [[H5::H5Library::open();]])],
  [-lhdf5])


### Image libraries
# : ${JPEG_PATH=/usr/sfw}
# Grr... jpeglib.h isn't especially well-behaved.
NCBI_CHECK_THIRD_PARTY_LIB(jpeg,
 [AC_LANG_PROGRAM([@%:@include <sys/types.h>
                   @%:@include <stdio.h>
                   extern "C" {
                   @%:@include <jpeglib.h>
                   }],
    [struct jpeg_decompress_struct cinfo;
     struct jpeg_error_mgr         jerr;
     cinfo.err = jpeg_std_error(&jerr);
 ])])

# : ${PNG_PATH=/usr/sfw}
NCBI_CHECK_THIRD_PARTY_LIB(png,
 [AC_LANG_PROGRAM([@%:@include <png.h>],
    [png_structp png_ptr
      = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 ])], $Z_LIBS, [], $Z_INCLUDE)

# : ${TIFF_PATH=/usr/sfw}
NCBI_CHECK_THIRD_PARTY_LIB(tiff,
 [AC_LANG_PROGRAM([@%:@include <tiffio.h>],
    [TIFF* tiff = TIFFOpen("foo", "r");])], $Z_LIBS, $JPEG_LIBS)
## etc.

# Paths?
with_ungif=$with_gif
NCBI_CHECK_THIRD_PARTY_LIB(gif,
 [AC_LANG_PROGRAM([extern "C" {
                  @%:@include <gif_lib.h>
                  }],
    [GifFileType* fp; return DGifSlurp(fp);])], $X_LIBS -lX11)
if test "$with_gif" = "no"; then
   NCBI_CHECK_THIRD_PARTY_LIB(ungif,
    [AC_LANG_PROGRAM([extern "C" {
                     @%:@include <gif_lib.h>
                     }],
       [GifFileType* fp; return DGifSlurp(fp);])], $X_LIBS -lX11)
else
   AC_DEFINE(HAVE_LIBUNGIF, 1, [Define to 1 if libungif is available.])
   UNGIF_INCLUDE=$GIF_INCLUDE
   UNGIF_LIBS=$GIF_LIBS
fi

case "$x_libraries" in */*) : ${XPM_PATH=`dirname "$x_libraries"`} ;; esac
NCBI_CHECK_THIRD_PARTY_LIB(Xpm,
 [AC_LANG_PROGRAM([@%:@include <X11/xpm.h>],
    [XpmImage image; XpmInfo info;
     XpmReadFileToXpmImage("foo", &image, &info);])], $X_LIBS -lX11, [],
    $X_CFLAGS)
# The use of X_CFLAGS is probably redundant, but shouldn't hurt.

if test "$with_gl2ps" != "no"; then
   if test "${with_gl2ps-yes}" != "yes"; then
      GL2PS_PATH=$with_gl2ps
   fi
   if test -d "$GL2PS_PATH"; then
      if test -d "$GL2PS_PATH/$compiler_vpfx$DEBUG_SFX$bit64_sfx"; then
         GL2PS_PATH=$GL2PS_PATH/$compiler_vpfx$DEBUG_SFX$bit64_sfx
      elif test -d "$GL2PS_PATH/$compiler_pfx$DEBUG_SFX$bit64_sfx"; then
         GL2PS_PATH=$GL2PS_PATH/$compiler_pfx$DEBUG_SFX$bit64_sfx
      elif test -d "$GL2PS_PATH/$DEBUG_SFX$bit64_sfx"; then
         GL2PS_PATH=$GL2PS_PATH/$DEBUG_SFX$bit64_sfx
      fi
      NCBI_FIX_DIR(GL2PS_PATH)
   fi
   NCBI_CHECK_THIRD_PARTY_LIB(gl2ps,
    [AC_LANG_PROGRAM([@%:@include <gl2ps.h>],
       [gl2psSpecial(GL2PS_SVG, "foo")])],
    [], [$OPENGL_LIBS $PNG_LIBS $Z_LIBS], [$OPENGL_INCLUDE])
fi
if test -n "$GL2PS_LIBS" -a -f "$GL2PS_PATH/lib/libgl2ps-static.a"; then
   GL2PS_STATIC_LIBS="-L$GL2PS_PATH/lib -lgl2ps-static"
else
   GL2PS_STATIC_LIBS=$GL2PS_LIBS
fi

## FreeType and FTGL
if test "$with_freetype" != "no" ; then
   ft2pc="env PKG_CONFIG_PATH=$FREETYPE_PATH/lib/pkgconfig pkg-config freetype2"
   if $ft2pc --exists >/dev/null 2>&1; then
      freetype_config=$ft2pc
      FREETYPE_PATH=`$ft2pc --variable=exec_prefix`
   else
      : ${FREETYPE_BINPATH=$FREETYPE_PATH/bin}
      AC_PATH_PROG(freetype_config, freetype-config, [],
                   [$FREETYPE_BINPATH:$PATH])
   fi
   if test -n "$freetype_config" ; then
      : ${FREETYPE_INCLUDE=`$freetype_config --cflags`}
      NCBI_RPATHIFY_OUTPUT_COND(FREETYPE_LIBS, $freetype_config --libs,
         [$no_usr_lib])
      case "$host_os:$bit64_sfx" in
         solaris*:64 )
            ftprefix=`$freetype_config --exec-prefix`
            if test -d "$ftprefix/lib/64"; then
               FREETYPE_LIBS=`echo $FREETYPE_LIBS \
                   | sed -e "s,$ftprefix/lib ,$ftprefix/lib/64 ,g"`
            fi
            ;;
      esac
      AC_CACHE_CHECK([whether FREETYPE_INCLUDE needs doctoring],
                     ncbi_cv_lib_freetype_fix_include,
         [CPPFLAGS="$FREETYPE_INCLUDE $orig_CPPFLAGS"
          AC_COMPILE_IFELSE(
             [AC_LANG_PROGRAM(
                 [[@%:@include <ft2build.h>]], [])],
             [ncbi_cv_lib_freetype_fix_include=no],
             [ncbi_cv_lib_freetype_fix_include=yes])])
      if test "$ncbi_cv_lib_freetype_fix_include" = yes; then
         FREETYPE_INCLUDE=`echo "$FREETYPE_INCLUDE" |\
             sed -e 's:\(-I[[^ ]]*\)\(/freetype2\):\1 \1\2:g'`
      fi
      AC_CACHE_CHECK([whether FreeType works], ncbi_cv_lib_freetype,
         [CPPFLAGS="$FREETYPE_INCLUDE $orig_CPPFLAGS"
          LIBS="$FREETYPE_LIBS $orig_LIBS"
          AC_LINK_IFELSE(
             [AC_LANG_PROGRAM(
                 [[@%:@include <ft2build.h>
                   @%:@include FT_FREETYPE_H]],
                 [[FT_Select_Charmap(NULL, ft_encoding_unicode);]])],
             [ncbi_cv_lib_freetype=yes], [ncbi_cv_lib_freetype=no])])
      if test "$ncbi_cv_lib_freetype" = no; then
         NCBI_MISSING_PACKAGE(freetype)
      fi
   else
      NCBI_MISSING_PACKAGE(freetype)
   fi
fi
if test "$with_freetype" = "no" ; then
   FREETYPE_PATH="No_FREETYPE"
   FREETYPE_INCLUDE=
   FREETYPE_LIBS=
else
   NCBI_PACKAGE(FreeType)
   AC_DEFINE(HAVE_FREETYPE, 1, [Define to 1 if FreeType is available.])
fi

case "$with_ftgl" in
   yes | '' ) ;;
   *        ) FTGL_PATH=$with_ftgl ;;
esac

if test -d "$FTGL_PATH"; then
   NCBI_FIX_DIR(FTGL_PATH)
fi
if test -d "$FTGL_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}/lib"; then
   FTGL_LIBDIR=$FTGL_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}/lib
elif test -d "$FTGL_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}/lib"; then
   FTGL_LIBDIR=$FTGL_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}/lib
fi
NCBI_FIX_DIR(FTGL_LIBDIR)
NCBI_RPATHIFY(FTGL_LIBPATH, $FTGL_LIBDIR)

NCBI_CHECK_THIRD_PARTY_LIB(ftgl,
  [AC_LANG_PROGRAM([[@%:@include <FTGL/ftgl.h>]], [[FTSimpleLayout layout;]])],
  [$FREETYPE_LIBS], [], [$FREETYPE_INCLUDE])


NCBI_CHECK_THIRD_PARTY_LIB(magic,
   [AC_LANG_PROGRAM([@%:@include <magic.h>],
       [magic_t m = magic_open(17);])])


# Mimetic
case "$with_mimetic" in
   yes | '' ) ;;
   *        ) MIMETIC_PATH=$with_mimetic ;;
esac
if test -d "$MIMETIC_PATH"; then
   NCBI_FIX_DIR(MIMETIC_PATH)
fi
for d in "$MIMETIC_LIBDIR" \
         "$MIMETIC_PATH/${compiler_vpfx}${DEBUG_SFX}${bit64_sfx}/lib" \
         "$MIMETIC_PATH/${compiler_pfx}${DEBUG_SFX}${bit64_sfx}/lib" \
         "$MIMETIC_PATH/lib${bit64_sfx}" \
         "$MIMETIC_PATH/${compiler_vpfx}${DEBUG_SFX}/lib" \
         "$MIMETIC_PATH/${compiler_pfx}${DEBUG_SFX}/lib" \
         "$MIMETIC_PATH/lib"; do
   if test -d "$d"; then
      MIMETIC_LIBDIR=$d
      break
   fi
done
NCBI_RPATHIFY(MIMETIC_LIBPATH, $MIMETIC_LIBDIR)

NCBI_CHECK_THIRD_PARTY_LIB(mimetic,
   [AC_LANG_PROGRAM([@%:@include <mimetic/mimetic.h>],
       [mimetic::MimeEntity me;])])


# gSOAP++
case "$with_gsoap" in
   yes | '' ) ;;
   *        ) GSOAP_PATH=$with_gsoap ;;
esac
if test -d "$GSOAP_PATH"; then
   NCBI_FIX_DIR(GSOAP_PATH)
fi
for d in "$GSOAP_LIBDIR" \
         "$GSOAP_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}/lib" \
         "$GSOAP_PATH/${compiler_pfx}${DEBUG_SFX}${mt_sfx}${bit64_sfx}/lib" \
         "$GSOAP_PATH/lib${bit64_sfx}" \
         "$GSOAP_PATH/${compiler_vpfx}${DEBUG_SFX}${mt_sfx}/lib" \
         "$GSOAP_PATH/${compiler_pfx}${DEBUG_SFX}${mt_sfx}/lib" \
         "$GSOAP_PATH/lib"; do
   if test -d "$d"; then
      GSOAP_LIBDIR=$d
      NCBI_FIX_DIR(GSOAP_LIBDIR)
      break
   fi
done
NCBI_RPATHIFY(GSOAP_LIBPATH, $GSOAP_LIBDIR)

: ${GSOAP_BINDIR=`dirname "$GSOAP_LIBDIR"`/bin}
AC_PATH_PROG(GSOAP_SOAPCPP2, soapcpp2, [], $GSOAP_BINDIR:$PATH)
AC_PATH_PROG(GSOAP_WSDL2H,   wsdl2h,   [], $GSOAP_BINDIR:$PATH)

NCBI_CHECK_THIRD_PARTY_LIB_EX(gsoap, GSOAP, gsoapssl++,
   [AC_LANG_PROGRAM([@%:@include <stdsoap2.h>
        SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultcode(struct soap*)
        { return NULL; }
        SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultsubcode(struct soap*)
        { return NULL; }
        SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultstring(struct soap*)
        { return NULL; }
        SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultdetail(struct soap*)
        { return NULL; }
        SOAP_FMAC3 const char* SOAP_FMAC4 soap_check_faultsubcode(struct soap*)
        { return NULL; }
        SOAP_FMAC3 const char* SOAP_FMAC4 soap_check_faultdetail(struct soap*)
        { return NULL; }
        SOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap*) { }
        SOAP_FMAC3 int SOAP_FMAC4 soap_putheader(struct soap*) { return 0; }
        SOAP_FMAC3 int SOAP_FMAC4 soap_getheader(struct soap*) { return 0; }
        SOAP_FMAC3 void SOAP_FMAC4 soap_serializefault(struct soap*) { }
        SOAP_FMAC3 int SOAP_FMAC4 soap_putfault(struct soap*) { return 0; }
        SOAP_FMAC3 int SOAP_FMAC4 soap_getfault(struct soap*) { return 0; }],
       [soap s;])],
   $OPENSSL_LIBS $Z_LIBS)


# Apache Avro
if test "$with_avro" != no; then
   case "$with_avro" in
      yes | '' ) ;;
      *        ) AVRO_PATH=$with_avro ;;
   esac
   NCBI_FIND_ARCH_PATH(AVRO)
   AVRO_PATH=$AVRO_ARCH_PATH
   if test -d "$AVRO_PATH$asan_sfx"; then
      AVRO_PATH="$AVRO_PATH$asan_sfx"
   fi
   if test -d "$AVRO_PATH"; then
      NCBI_FIX_DIR(AVRO_PATH)
   fi
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(avro, AVRO, avrocpp,
   [AC_LANG_PROGRAM([@%:@include <avro/Node.hh>],
      [avro::Name name("foo");])],
   [$BOOST_LIBPATH $BOOST_FILESYSTEM_LIBS $BOOST_SYSTEM_LIBS $BOOST_PROGRAM_OPTIONS_LIBS $BOOST_IOSTREAMS_LIBS $RT_LIBS $Z_LIBS $BZ2_LIBS],
   [],
   [$BOOST_INCLUDE])
if test -n "$AVRO_LIBS"; then
   if test -f "$AVRO_PATH/lib/libavrocpp_s.a"; then
      AVRO_STATIC_LIBS="$AVRO_LIBPATH -lavrocpp_s $BOOST_LIBPATH $BOOST_FILESYSTEM_LIBS $BOOST_SYSTEM_LIBS $BOOST_PROGRAM_OPTIONS_LIBS $BOOST_IOSTREAMS_LIBS $RT_LIBS $Z_LIBS $BZ2_LIBS"
   else
      AVRO_STATIC_LIBS=$AVRO_LIBS
   fi
   AC_PATH_PROG(AVROGENCPP, avrogencpp, [], [$AVRO_PATH/bin:$PATH])
fi


# USC Cereal (header-only)
case "$with_cereal" in
   yes | no | '' ) ;;
   *             ) CEREAL_PATH=$with_cereal ;;
esac
if test "$with_cereal" != no; then
   in_cereal=
   if test -d "$CEREAL_PATH"; then
      NCBI_FIX_DIR(CEREAL_PATH)
      in_cereal=" in $CEREAL_PATH"
   fi
   CEREAL_INCLUDE=-I$CEREAL_PATH/include
   AC_CACHE_CHECK([for USC Cereal$in_cereal], ncbi_cv_lib_cereal,
      [CPPFLAGS="$CEREAL_INCLUDE $orig_CPPFLAGS"
       AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <iostream>
                             @%:@include <cereal/archives/binary.hpp>]],
                           [[cereal::BinaryOutputArchive
                             archive(std::cout);]])],
          [ncbi_cv_lib_cereal=yes], [ncbi_cv_lib_cereal=no])])
    if test "$ncbi_cv_lib_cereal" = yes; then
       NCBI_PACKAGE(Cereal)
    else
       NCBI_MISSING_PACKAGE(cereal)
       CEREAL_INCLUDE=
    fi
fi


# SASL 2
NCBI_CHECK_THIRD_PARTY_LIB(sasl2,
 [AC_LANG_PROGRAM([[@%:@include <stdlib.h>
                    @%:@include <sasl/sasl.h>]],
   [[sasl_client_init(NULL);]])])


# legacy MongoDB
case "$with_mongodb" in
   yes | no | '' ) ;;
   *             ) MONGODB_PATH=$with_mongodb ;;
esac
if test -d "$MONGODB_PATH"; then
   NCBI_FIX_DIR(MONGODB_PATH)
fi
if test -d $MONGODB_PATH/lib${bit64_sfx}; then
   MONGODB_LIBDIR=$MONGODB_PATH/lib${bit64_sfx}
else
   MONGODB_LIBDIR=$MONGODB_PATH/lib
fi
# need Boost rpath
NCBI_RPATHIFY(MONGODB_LIBPATH, $MONGODB_LIBDIR)
NCBI_CHECK_THIRD_PARTY_LIB_EX(mongodb, MONGODB, mongoclient,
   [AC_LANG_PROGRAM([@%:@include <mongo/client/dbclient.h>],
      [std::vector<mongo::HostAndPort> v;
       mongo::DBClientReplicaSet client("foo", v);
       client.connect();])],
   [$BOOST_LIBPATH $boost_fs_lib $BOOST_REGEX_LIBS $BOOST_THREAD_LIBS $OPENSSL_LIBS $SASL2_LIBS], [],
   [$BOOST_INCLUDE])
# MongoDB's own library is normally static, but its supporting Boost
# libraries might not be by default.
if test -n "$MONGODB_LIBS"; then
   MONGODB_STATIC_LIBS="$MONGODB_LIBPATH -lmongoclient $BOOST_LIBPATH $boost_fs_static_lib $BOOST_REGEX_STATIC_LIBS $BOOST_THREAD_STATIC_LIBS $OPENSSL_LIBS $SASL2_LIBS"
else
   MONGODB_STATIC_LIBS=
fi


# MongoDB 3.x
if test "$with_mongodb3" != no; then
   case "$with_mongodb3" in
      yes | '' ) ;;
      *        ) MONGODB3_PATH=$with_mongodb3 ;;
   esac
   NCBI_FIND_ARCH_PATH(MONGODB3)
   MONGODB3_PATH=$MONGODB3_ARCH_PATH
   if test -d "$MONGODB3_PATH$asan_sfx"; then
      MONGODB3_PATH="$MONGODB3_PATH$asan_sfx"
   fi
   if test -d "$MONGODB3_PATH"; then
      NCBI_FIX_DIR(MONGODB3_PATH)
   fi
fi
if test -d $MONGODB3_PATH/lib${bit64_sfx}; then
   MONGODB3_LIBDIR=$MONGODB3_PATH/lib${bit64_sfx}
else
   MONGODB3_LIBDIR=$MONGODB3_PATH/lib
fi
m3pc="env PKG_CONFIG_PATH=$MONGODB3_LIBDIR/pkgconfig pkg-config libmongocxx"
if $m3pc --exists >/dev/null 2>&1; then
   MONGODB3_FULL_INCLUDE=`$m3pc --cflags`
   NCBI_RPATHIFY_OUTPUT(MONGODB3_FULL_LIBS, [$m3pc --libs --static],
      [$no_usr_lib])
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(mongodb3, MONGODB3, mongocxx,
   [AC_LANG_PROGRAM([@%:@include <mongocxx/client.hpp>],
      [mongocxx::client mongo_client;])],
   [], [$MONGODB3_FULL_LIBS],
   [$MONGODB3_FULL_INCLUDE $BOOST_INCLUDE])
if test -n "$MONGODB3_LIBS"; then
   MONGODB3_INCLUDE=$MONGODB3_FULL_INCLUDE
   MONGODB3_LIBS=$MONGODB3_FULL_LIBS
   if $m3pc-static --exists >/dev/null 2>&1; then
      MONGODB3_STATIC_LIBS=`$m3pc-static --libs --static`
   elif test -f $MONGODB3_LIBDIR/libmongocxx-static.a; then
      MONGODB3_STATIC_LIBS=`echo "$MONGODB3_LIBS" | \
        [sed -e 's/-lmongo[^ ]*/&-static/g; s/-lbson[^ ]*/&-static/g' \
             -e 's/\(-l[^ ]*-static[^ ]*\)-static/\1/g']`
   else
      MONGODB3_STATIC_LIBS=$MONGODB3_LIBS
   fi
   if test -n "$ZSTD_LIBS"; then
      zsed="s@ -lzstd @ $ZSTD_LIBS @; s/^ //; s/ $//"
      MONGODB3_LIBS=`echo " $MONGODB3_LIBS " | sed -e "$zsed"`
      MONGODB3_STATIC_LIBS=`echo " $MONGODB3_STATIC_LIBS " | sed -e "$zsed"`
   fi
fi


# LevelDB
if test "$with_leveldb" != no; then
   case "$with_leveldb" in
      yes | '' ) ;;
      *        ) LEVELDB_PATH=$with_leveldb ;;
   esac
   NCBI_FIND_ARCH_PATH(LEVELDB)
   LEVELDB_PATH=$LEVELDB_ARCH_PATH
   if test -d "$LEVELDB_PATH"; then
      NCBI_FIX_DIR(LEVELDB_PATH)
   fi
fi
if test -d $LEVELDB_PATH/lib${bit64_sfx}; then
   LEVELDB_LIBDIR=$LEVELDB_PATH/lib${bit64_sfx}
else
   LEVELDB_LIBDIR=$LEVELDB_PATH/lib
fi
NCBI_CHECK_THIRD_PARTY_LIB(leveldb,
  [AC_LANG_PROGRAM([[@%:@include <leveldb/db.h>
                     using namespace leveldb;]],
     [[DB* db; Status status = DB::Open(Options(), "foo", &db);]])])


# liburing
if test "$with_liburing" != no; then
   case "$with_liburing" in
      yes | '' ) ;;
      *        ) LIBURING_PATH=$with_liburing ;;
   esac
   NCBI_FIND_ARCH_PATH(LIBURING)
   LIBURING_PATH=$LIBURING_ARCH_PATH
   if test -d "$LIBURING_PATH"; then
      NCBI_FIX_DIR(LIBURING_PATH)
   fi
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(liburing, LIBURING, uring,
  [AC_LANG_PROGRAM([[@%:@include <liburing.h>]],
     [[io_uring_free_probe(io_uring_get_probe());]])])



# RocksDB
if test "$with_rocksdb" != no; then
   case "$with_rocksdb" in
      yes | '' ) ;;
      *        ) ROCKSDB_PATH=$with_rocksdb ;;
   esac
   NCBI_FIND_ARCH_PATH(ROCKSDB)
   ROCKSDB_PATH=$ROCKSDB_ARCH_PATH
   if test -d "$ROCKSDB_PATH$asan_sfx"; then
      ROCKSDB_PATH="$ROCKSDB_PATH$asan_sfx"
   fi
   if test -d "$ROCKSDB_PATH"; then
      NCBI_FIX_DIR(ROCKSDB_PATH)
   fi
fi
if test -d $ROCKSDB_PATH/lib${bit64_sfx}; then
   ROCKSDB_LIBDIR=$ROCKSDB_PATH/lib${bit64_sfx}
else
   ROCKSDB_LIBDIR=$ROCKSDB_PATH/lib
fi
NCBI_CHECK_THIRD_PARTY_LIB(rocksdb,
  [AC_LANG_PROGRAM([[@%:@include <rocksdb/db.h>
                     using namespace rocksdb;]],
     [[DB* db; Status status = DB::Open(Options(), "foo", &db);]])],
  [$LIBURING_LIBS $BZ2_LIBS $Z_LIBS $ZSTD_LIBS])


# Google Mock
case "$with_gmock" in
   yes | no | '' ) ;;
   *             ) GMOCK_PATH=$with_gmock ;;
esac
if test -d "$GMOCK_PATH"; then
   NCBI_FIX_DIR(GMOCK_PATH)
   NCBI_FIND_ARCH_PATH(GMOCK)
   GMOCK_LIBDIR=$GMOCK_ARCH_PATH/lib
   NCBI_FIX_DIR(GMOCK_LIBDIR)
fi
NCBI_RPATHIFY(GMOCK_LIBPATH, $GMOCK_LIBDIR)
NCBI_CHECK_THIRD_PARTY_LIB(gmock,
   [AC_LANG_PROGRAM([@%:@include <gmock/gmock.h>],
      [int    my_argc;
       char** my_argv;
       testing::InitGoogleMock(&my_argc, my_argv);])],
   [-lgtest])
if test -n "$GMOCK_LIBS"; then
   if test -f "$GMOCK_LIBDIR/libgmock-static.a"; then
      GMOCK_STATIC_LIBS="-L$GMOCK_LIBDIR -lgmock-static -lgtest-static"
   else
      GMOCK_STATIC_LIBS=$GMOCK_LIBS
   fi
fi


# LAPACK
CPPFLAGS="-DHAVE_LAPACK_CONFIG_H $orig_CPPFLAGS"
case "$with_lapack" in
   yes | no | '' ) ;;
   *             ) LAPACK_PATH=$with_lapack ;;
esac
if test -d "$LAPACK_PATH"; then
   NCBI_FIX_DIR(LAPACK_PATH)
   CPPFLAGS="-I$LAPACK_PATH/include $CPPFLAGS"
fi
AC_LANG_PUSH(C)
AC_CHECK_HEADERS(lapacke.h lapacke/lapacke.h clapack.h Accelerate/Accelerate.h)
AC_LANG_POP(C)
if test "$ac_cv_header_clapack_h:$ac_cv_header_Accelerate_Accelerate_h" != no:no; then
   AC_CHECK_TYPES([__CLPK_integer], [], [],
      [[@%:@ifdef HAVE_CLAPACK_H
        @%:@  include <clapack.h>
        @%:@else
        @%:@  include <Accelerate/Accelerate.h>
        @%:@endif]])
fi

NCBI_CHECK_THIRD_PARTY_LIB(lapack,
   [AC_LANG_PROGRAM([[extern "C" int dsyev_();]],
      [[return dsyev_();]])],
   [-lblas])

# LMDB
NCBI_CHECK_THIRD_PARTY_LIB(lmdb,
   [AC_LANG_PROGRAM([[@%:@include <lmdb.h>]],
      [[MDB_env *env; return mdb_env_create(&env);]])],
   [$THREAD_LIBS])
if test -z "$LMDB_LIBS"; then
   lmdblocal=util/lmdb
   AC_MSG_NOTICE([using local LMDB copy in $lmdblocal])
   LMDB_PATH="<$lmdblocal>"
   LMDB_INCLUDE="-I\$(includedir)/$lmdblocal -I\$(includedir0)/$lmdblocal"
   # In MT builds, ORIG_LIBS already contains THREAD_LIBS.  However,
   # LMDB is always threaded, and may need explicit THREAD_LIBS when
   # used statically.
   LMDB_LIBS="$THREAD_LIBS"
   # LMDB_LIBS="-llmdb $THREAD_LIBS"
   LMDB_LIB="lmdb"
   AC_DEFINE(USE_LOCAL_LMDB, 1, [Define to 1 if using a local copy of LMDB.])
   NCBI_PACKAGE(LMDB)
   NCBI_PACKAGE(LocalLMDB)
fi
if test "$with_lmdb" != no -a -f "$LMDB_PATH/lib/liblmdb-static.a"; then
    LMDB_STATIC_LIBS="-L$LMDB_PATH/lib -llmdb-static"
    if test "x$with_bin_release" = "xyes"; then
       LMDB_LIBS=$LMDB_STATIC_LIBS
    fi
else
    LMDB_STATIC_LIBS=$LMDB_LIBS
fi

# libuv
case "$with_libuv" in
   yes | no | '' ) ;;
   *             ) LIBUV_PATH=$with_libuv ;;
esac
if test -d "$LIBUV_PATH"; then
   NCBI_FIX_DIR(LIBUV_PATH)
   for d in "$LIBUV_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$bit64_sfx/lib" \
            "$LIBUV_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$bit64_sfx/lib" \
            "$LIBUV_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx/lib" \
            "$LIBUV_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx/lib" \
            "$LIBUV_PATH/lib$bit64_sfx" "$LIBUV_PATH/lib"; do
      if test -d "$d"; then
         LIBUV_LIBDIR=$d
         NCBI_FIX_DIR(LIBUV_LIBDIR)
         break
      fi
   done
fi
NCBI_RPATHIFY(LIBUV_LIBPATH, $LIBUV_LIBDIR)
NCBI_CHECK_THIRD_PARTY_LIB_EX(libuv, LIBUV, uv,
   [AC_LANG_PROGRAM([[@%:@include <uv.h>]],
      [[uv_mutex_t m; return uv_mutex_init(&m);]])])
if test "$with_libuv" != no -a -f "$LIBUV_LIBDIR/libuv-static.a"; then
    LIBUV_STATIC_LIBS="-L$LIBUV_LIBDIR -luv-static"
    if test "x$with_bin_release" = "xyes"; then
       LIBUV_LIBS=$LIBUV_STATIC_LIBS
    fi
else
    LIBUV_STATIC_LIBS=$LIBUV_LIBS
fi

# libssh2
case "$with_libssh2" in
   yes | no | '' ) ;;
   *             ) LIBSSH2_PATH=$with_libssh2 ;;
esac
if test -d "$LIBSSH2_PATH"; then
   NCBI_FIX_DIR(LIBSSH2_PATH)
   for d in "$LIBSSH2_PATH/$compiler_vpfx$DEBUG_SFX$bit64_sfx/lib" \
            "$LIBSSH2_PATH/$compiler_pfx$DEBUG_SFX$bit64_sfx/lib" \
            "$LIBSSH2_PATH/$compiler_vpfx$DEBUG_SFX/lib" \
            "$LIBSSH2_PATH/$compiler_pfx$DEBUG_SFX/lib" \
            "$LIBSSH2_PATH/lib$bit64_sfx" "$LIBSSH2_PATH/lib"; do
      if test -d "$d"; then
         LIBSSH2_LIBDIR=$d
         NCBI_FIX_DIR(LIBSSH2_LIBDIR)
         break
      fi
   done
fi
NCBI_RPATHIFY(LIBSSH2_LIBPATH, $LIBSSH2_LIBDIR)
NCBI_CHECK_THIRD_PARTY_LIB_EX(libssh2, LIBSSH2, ssh2,
   [AC_LANG_PROGRAM([[@%:@include <libssh2.h>]],
      [[return libssh2_init(LIBSSH2_INIT_NO_CRYPTO);]])],
   [$OPENSSL_LIBS])
if test "$with_libssh2" != no -a -f "$LIBSSH2_LIBDIR/libssh2-static.a"; then
    LIBSSH2_STATIC_LIBS="-L$LIBSSH2_LIBDIR -lssh2-static $OPENSSL_LIBS"
else
    LIBSSH2_STATIC_LIBS=$LIBSSH2_LIBS
fi

# Datastax Cassandra driver
case "$with_cassandra" in
   yes | no | '' ) ;;
   *             ) CASSANDRA_PATH=$with_cassandra ;;
esac
if test -d "$CASSANDRA_PATH"; then
   NCBI_FIND_ARCH_PATH(CASSANDRA)
   CASSANDRA_PATH=$CASSANDRA_ARCH_PATH
   NCBI_FIX_DIR(CASSANDRA_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(cassandra,
   [AC_LANG_PROGRAM([[@%:@include <cassandra.h>]],
      [[CassCluster* c = cass_cluster_new();]])],
   [$LIBSSH2_LIBS $LIBUV_LIBS $KRB5_LIBS])
if test "$with_cassandra" != no -a \
     -f "$CASSANDRA_PATH/lib/libcassandra_static.a"; then
    CASSANDRA_STATIC_LIBS="-L$CASSANDRA_PATH/lib -lcassandra_static $LIBSSH2_STATIC_LIBS $LIBUV_STATIC_LIBS $KRB5_LIBS"
else
    CASSANDRA_STATIC_LIBS=$CASSANDRA_LIBS
fi

# HTTP/2 libraries
case "$with_nghttp2" in
   yes | no | '' ) ;;
   *             ) NGHTTP2_PATH=$with_nghttp2 ;;
esac
if test -d "$NGHTTP2_PATH"; then
   NCBI_FIX_DIR(NGHTTP2_PATH)
   NCBI_FIND_ARCH_PATH(NGHTTP2)
   NGHTTP2_LIBDIR=$NGHTTP2_ARCH_PATH/lib
   NCBI_FIX_DIR(NGHTTP2_LIBDIR)
fi
NCBI_RPATHIFY(NGHTTP2_LIBPATH, $NGHTTP2_LIBDIR)
NCBI_CHECK_THIRD_PARTY_LIB(nghttp2,
   [AC_LANG_PROGRAM([[@%:@include <nghttp2/nghttp2.h>]],
       [[nghttp2_error_callback cb;
         const char* s = nghttp2_http2_strerror(NGHTTP2_ERR_EOF);]])])
if test "$with_nghttp2" != no -a \
     -f "$NGHTTP2_LIBDIR/libnghttp2-static.a"; then
   NGHTTP2_STATIC_LIBS="-L$NGHTTP2_LIBDIR -lnghttp2-static"
   if test "x$with_bin_release" = "xyes"; then
      NGHTTP2_LIBS=$NGHTTP2_STATIC_LIBS
   fi
else
   NGHTTP2_STATIC_LIBS=$NGHTTP2_LIBS
fi

case "$with_h2o" in
   yes | no | '' ) ;;
   *             ) H2O_PATH=$with_h2o ;;
esac
if test -d "$H2O_PATH"; then
   NCBI_FIND_ARCH_PATH(H2O)
   H2O_PATH=$H2O_ARCH_PATH
   NCBI_FIX_DIR(H2O_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(h2o,
   [AC_LANG_PROGRAM([[@%:@include <h2o.h>>]],
       [[h2o_init_request(NULL, NULL, NULL);]])],
   [$LIBUV_LIBS $OPENSSL_LIBS $Z_LIBS], [], [$LIBUV_INCLUDE])
if test "$with_h2o" != no -a \
     -f "$H2O_PATH/lib/libh2o-static.a"; then
    H2O_STATIC_LIBS="-L$H2O_PATH/lib -lh2o-static $LIBUV_STATIC_LIBS $OPENSSL_LIBS $Z_LIBS"
else
    H2O_STATIC_LIBS=$H2O_LIBS
fi

case "$with_influxdb" in
   yes | '' ) ;;
   no       ) ncbi_cv_lib_influxdb=no ;;
   *        ) INFLUXDB_PATH=$with_influxdb ;;
esac
if test -d "$INFLUXDB_PATH"; then
   INFLUXDB_INCLUDE=-I$INFLUXDB_PATH/include
   in_path=" in $INFLUXDB_PATH"
else
   in_path=
fi
CPPFLAGS="$orig_CPPFLAGS $INFLUXDB_INCLUDE"
AC_CACHE_CHECK([for influxdb-cpp$in_path],
   ncbi_cv_lib_influxdb,
   [AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM([[@%:@include <influxdb.hpp>]],
           [[auto& b = influxdb_cpp::builder().meas("foo");]])],
       ncbi_cv_lib_influxdb=yes, ncbi_cv_lib_influxdb=no)])
if test $ncbi_cv_lib_influxdb = yes; then
   NCBI_PACKAGE(INFLUXDB)
else
   INFLUXDB_INCLUDE=
   NCBI_MISSING_PACKAGE(influxdb)
fi


NCBI_CHECK_THIRD_PARTY_LIB_EX(libxlsxwriter, LIBXLSXWRITER, xlsxwriter,
   [AC_LANG_PROGRAM([[@%:@include <xlsxwriter.h>]],
      [[lxw_workbook* wb = workbook_new("conftest.xlsx");]])],
   [], [$Z_LIBS])
if test "$with_libxlsxwriter" != no -a \
     -f "$LIBXLSXWRITER_PATH/lib/libxlsxwriter-static.a"; then
    LIBXLSXWRITER_STATIC_LIBS="-L$LIBXLSXWRITER_PATH/lib -lxlsxwriter-static"
else
    LIBXLSXWRITER_STATIC_LIBS=$LIBXLSXWRITER_LIBS
fi

case "$with_grpc" in
   yes | no | '' ) ;;
   *             ) GRPC_PATH=$with_grpc ;;
esac
if test -d "$GRPC_PATH"; then
   NCBI_FIX_DIR(GRPC_PATH)
   for d in "$GRPC_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$bit64_sfx$asan_sfx" \
            "$GRPC_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$bit64_sfx$asan_sfx" \
            "$GRPC_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$asan_sfx" \
            "$GRPC_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$asan_sfx" \
            "$GRPC_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$bit64_sfx" \
            "$GRPC_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$bit64_sfx" \
            "$GRPC_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx" \
            "$GRPC_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx"; do
      if test -d "$d"; then
         GRPC_PATH=$d
         NCBI_FIX_DIR(GRPC_PATH)
         break
      fi
   done
fi

: ${PROTOBUF_PATH=$GRPC_PATH}

PROTOBUF_SFX=
if test -n "$D_SFX"; then
   if ls $PROTOBUF_PATH/lib*/libprotobuf$D_SFX.* >/dev/null 2>&1; then
      PROTOBUF_SFX=$D_SFX
   else
      for ext in .a .so .dylib; do
         path=`$CXX -B$PROTOBUF_PATH/ -print-file-name=libprotobuf$D_SFX.$ext \
               2>/dev/null`
         case "$path" in
            */* ) PROTOBUF_SFX=$D_SFX; break ;;
         esac
      done
   fi
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(protobuf, PROTOBUF, [protobuf$PROTOBUF_SFX],
   [AC_LANG_PROGRAM([[@%:@include <google/protobuf/type.pb.h>]],
       [[google::protobuf::Type t;]])],
   [], [$Z_LIBS])
if test -n "$PROTOBUF_LIBS"; then
   AC_PATH_PROG(PROTOC, protoc, [], [$PROTOBUF_PATH/bin:$PATH])
   if test ! -x "$PROTOC"; then
      NCBI_MISSING_PACKAGE(grpc)
      NCBI_MISSING_PACKAGE(protobuf)
   fi
   PROTOBUF_BIN=`dirname $PROTOC`
else
   NCBI_MISSING_PACKAGE(grpc)
fi

grpc_pc=pkg-config
if test -n "$GRPC_PATH"; then
   for d in "$GRPC_PATH/lib$bit64_sfx" "$GRPC_PATH/lib"; do
      if test -d "$d/pkgconfig"; then
         grpc_pc="env PKG_CONFIG_PATH=$d/pkgconfig pkg-config"
         break
      fi
   done
fi
if $grpc_pc grpc++ --exists 2>/dev/null; then
   GRPC_SED=sed
   if test -f "$GRPC_PATH/lib/libboringssl.a"; then
      GRPC_SED="sed -e s/-lssl/-lboringssl/g -e s/-lcrypto/-lboringcrypto/g"
   fi
   if test -f /usr/lib/libssl.dylib -a \
             x"`$grpc_pc grpc++ --variable=prefix`" != x/sw; then
      GRPC_SED="$GRPC_SED -e s,-L/sw/lib,,"
   fi
   if test "$GRPC_SED" = sed; then
      GRPC_SED=cat
   fi
   GRPC_CONFIG_LIBS="`$grpc_pc grpc++ grpc --libs | $GRPC_SED`"
else
   GRPC_CONFIG_LIBS=
   if test -n "$GRPC_PATH"; then
      in_path=" in $GRPC_PATH"
      CPPFLAGS="-I$GRPC_PATH/include $orig_CPPFLAGS"
      LIBS="$PROTOBUF_LIBPATH -L$GRPC_PATH/lib$bit64_sfx -L$GRPC_PATH/lib -lcares"
      LIBS="$LIBS $orig_LIBS"
   else
      LIBS="-lcares $orig_LIBS"
   fi
   AC_MSG_CHECKING([for libcares$in_path])
   AC_LINK_IFELSE(
      [AC_LANG_PROGRAM([@%:@include <ares.h>], [ares_library_init(0);])],
      [CARES_LIBS=-lcares; AC_MSG_RESULT([yes])],
      [CARES_LIBS=; AC_MSG_RESULT([no])])
   
   if test -f "$GRPC_PATH/lib/libboringssl.a"; then
      GRPC_LDEP="-lboringssl -lboringcrypto"
   else
      GRPC_LDEP=$OPENSSL_LIBS
   fi
fi
# In MT builds, ORIG_LIBS already contains THREAD_LIBS.  However,
# GRPC is always threaded, and may need explicit THREAD_LIBS when
# used statically.
if test "$with_mt" = no; then
   GRPC_LDEP="$GRPC_LDEP $THREAD_LIBS"
fi

NCBI_CHECK_THIRD_PARTY_LIB_EX(grpc, GRPC, grpc++,
   [AC_LANG_PROGRAM([[@%:@include <grpc++/grpc++.h>]],
       [[return grpc::Version().size();]])],
   [${GRPC_CONFIG_LIBS--lgrpc -lgpr $CARES_LIBS $GRPC_LDEP}],
   [$PROTOBUF_LIBS $Z_LIBS], [$PROTOBUF_INCLUDE])
if test -n "$GRPC_LIBS"; then
   if test -n "$GRPC_CONFIG_LIBS"; then
      GRPC_LIBS="$GRPC_CONFIG_LIBS $PROTOBUF_LIBS $GRPC_LDEP"
      GRPC_UNSECURE_LIBS="`$grpc_pc grpc++_unsecure grpc_unsecure --libs`"
      for x in address_sorting upb cares; do
         case " $GRPC_LIBS ::: $GRPC_UNSECURE_LIBS " in
            *:::*" -l$x "* ) ;;
            *" -l$x "* ) GRPC_UNSECURE_LIBS="$GRPC_UNSECURE_LIBS -l$x" ;;
         esac
      done
      GRPC_UNSECURE_LIBS="$GRPC_UNSECURE_LIBS $PROTOBUF_LIBS $GRPC_LDEP"
   else
      LDFLAGS="$orig_LDFLAGS $GRPC_LIBPATH"
      AC_CHECK_LIB(address_sorting, address_sorting_rfc_6724_sort,
         [GRPC_LIBS="$GRPC_LIBS -laddress_sorting"], [])
      LDFLAGS=$orig_LDFLAGS
      GRPC_UNSECURE_LIBS=`echo $GRPC_LIBS \
         | sed -e 's/\(-lgrpc+*\)/\1_unsecure/g'`
      GRPC_LIBS="$GRPC_LIBS $GRPC_LDEP"
   fi 
   GRPC_REFLECTION_LIBS="$WHOLE_ARCHIVE $NO_AS_NEEDED $GRPC_LIBPATH"
   GRPC_REFLECTION_LIBS="$GRPC_REFLECTION_LIBS -lgrpc++_reflection"
   GRPC_REFLECTION_LIBS="$GRPC_REFLECTION_LIBS $NO_WHOLE_ARCHIVE $AS_NEEDED"
   AC_PATH_PROG(GRPC_CPP_PLUGIN, grpc_cpp_plugin, [],
      [$GRPC_PATH/bin:$PROTOBUF_PATH/bin:$PATH])
   if test ! -x "$GRPC_CPP_PLUGIN"; then
      NCBI_MISSING_PACKAGE(grpc)
   fi
   GRPC_BIN=`dirname $GRPC_CPP_PLUGIN`
fi

case "$with_msgsl" in
   yes | '' ) ;;
   no       ) ncbi_cv_lib_msgsl=no ;;
   *        ) MSGSL_PATH=$with_msgsl ;;
esac
if test -d "$MSGSL_PATH"; then
   MSGSL_INCLUDE=-I$MSGSL_PATH/include
   in_path=" in $MSGSL_PATH"
else
   in_path=
fi
CPPFLAGS="$orig_CPPFLAGS $MSGSL_INCLUDE"
AC_CHECK_HEADERS([gsl/gsl], [NCBI_PACKAGE(MSGSL)],
   [MSGSL_INCLUDE=; NCBI_MISSING_PACKAGE(msgsl)])

case "$with_aws_sdk" in
   yes | no | '' ) ;;
   *             ) AWS_SDK_PATH=$with_aws_sdk ;;
esac
if test -d "$AWS_SDK_PATH"; then
   NCBI_FIND_ARCH_PATH(AWS_SDK)
   AWS_SDK_PATH=$AWS_SDK_ARCH_PATH
   NCBI_FIX_DIR(AWS_SDK_PATH)
fi
AWS_SDK_LDEP=
AWS_SDK_STATIC_LDEP=
for d in "$AWS_SDK_PATH/lib$bit64_sfx" "$AWS_SDK_PATH/lib" \
         /usr/lib/$multiarch /usr/lib$bit64_sfx /usr/lib \
         /usr/local/lib$bit64_sfx /usr/local/lib; do
    if test -f "$d/libaws-cpp-sdk-s3.a"; then
       AWS_SDK_LIBDIR=$d
       if test -f "$AWS_SDK_LIBDIR/libaws-c-event-stream.a"; then
          AWS_SDK_LDEP="-laws-c-event-stream -laws-checksums -laws-c-common"
          AWS_SDK_STATIC_LDEP="-laws-c-event-stream-static -laws-checksums-static -laws-c-common-static"
       fi
       break
    fi
done
NCBI_CHECK_THIRD_PARTY_LIB_EX(aws_sdk, AWS_SDK, aws-cpp-sdk-s3,
   [AC_LANG_PROGRAM([[@%:@include <aws/s3/S3Client.h>
                      @%:@include <aws/ec2/EC2Client.h>]],
       [[Aws::S3::S3Client s3cli;
         Aws::EC2::EC2Client ec2cli;]])],
   [-laws-cpp-sdk-ec2 -laws-cpp-sdk-core $AWS_SDK_LDEP],
   [$CURL_LIBS $OPENSSL_LIBS $Z_LIBS])
if test "$with_aws_sdk" != no -a \
     -f "$AWS_SDK_LIBDIR/libaws-cpp-sdk-s3-static.a"; then
    AWS_SDK_STATIC_LIBS="-L$AWS_SDK_LIBDIR -laws-cpp-sdk-s3-static -laws-cpp-sdk-ec2-static -laws-cpp-sdk-core-static $AWS_SDK_STATIC_LDEP"
else
    AWS_SDK_STATIC_LIBS=$AWS_SDK_LIBS
fi

case "$with_crc32c" in
   no       ) ;;
   yes | "" ) ;;
   *        ) CRC32C_PATH=$with_crc32c ;;
esac
if test -d "$CRC32C_PATH"; then
   NCBI_FIND_ARCH_PATH(CRC32C)
   CRC32C_PATH=$CRC32C_ARCH_PATH
   NCBI_FIX_DIR(CRC32C_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(crc32c,
   [AC_LANG_PROGRAM([@%:@include <crc32c/crc32c.h>],
      [crc32c_value((const uint8_t*)"foo", 3);])])
if test "$with_crc32c" != no \
   -a -f "$CRC32C_PATH/lib/libcrc32c-static.a"; then
   CRC32C_STATIC_LIBS="-L$CRC32C_PATH/lib -lcrc32c-static"
fi

case "$with_google_cloud" in
   no       ) ;;
   yes | "" ) ;;
   *        ) GOOGLE_CLOUD_PATH=$with_google_cloud ;;
esac
if test -d "$GOOGLE_CLOUD_PATH"; then
   NCBI_FIND_ARCH_PATH(GOOGLE_CLOUD)
   GOOGLE_CLOUD_PATH=$GOOGLE_CLOUD_ARCH_PATH
   if test -d "$GOOGLE_CLOUD_PATH$asan_sfx"; then
      GOOGLE_CLOUD_PATH="$GOOGLE_CLOUD_PATH$asan_sfx"
   fi
   NCBI_FIX_DIR(GOOGLE_CLOUD_PATH)
fi
if test -d $GOOGLE_CLOUD_PATH/lib${bit64_sfx}; then
   GOOGLE_CLOUD_LIBDIR=$GOOGLE_CLOUD_PATH/lib${bit64_sfx}
else
   GOOGLE_CLOUD_LIBDIR=$GOOGLE_CLOUD_PATH/lib
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(google_cloud, GOOGLE_CLOUD,
   google_cloud_cpp_storage,
   [AC_LANG_PROGRAM([@%:@include <google/cloud/storage/client.h>],
       [google::cloud::storage::Client client])],
   [-lgoogle_cloud_cpp_common],
   [$CRC32C_LIBS $GRPC_LIBS $CURL_LIBS $OPENSSL_LIBS $Z_LIBS],
   [$GRPC_INCLUDE])

NCBI_CHECK_THIRD_PARTY_LIB(hiredis,
   [AC_LANG_PROGRAM([[@%:@include <hiredis/hiredis.h>]],
       [[redisReader* r = redisReaderCreate();]])])
if test "$with_hiredis" != no \
      -a -f "$HIREDIS_PATH/lib/libhiredis-static.a"; then
    HIREDIS_STATIC_LIBS="-L$HIREDIS_PATH/lib -lhiredis-static"
else
    HIREDIS_STATIC_LIBS=$HIREDIS_LIBS
fi

case "$with_apache_arrow" in
   yes | no | '' ) ;;
   *             ) APACHE_ARROW_PATH=$with_apache_arrow ;;
esac
if test -d "$APACHE_ARROW_PATH"; then
   NCBI_FIX_DIR(APACHE_ARROW_PATH)
   for d in "$APACHE_ARROW_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$bit64_sfx$asan_sfx" \
            "$APACHE_ARROW_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$bit64_sfx$asan_sfx" \
            "$APACHE_ARROW_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$asan_sfx" \
            "$APACHE_ARROW_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$asan_sfx" \
            "$APACHE_ARROW_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx$bit64_sfx" \
            "$APACHE_ARROW_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx$bit64_sfx" \
            "$APACHE_ARROW_PATH/$compiler_vpfx$DEBUG_SFX$mt_sfx" \
            "$APACHE_ARROW_PATH/$compiler_pfx$DEBUG_SFX$mt_sfx"; do
      if test -d "$d"; then
         APACHE_ARROW_PATH=$d
         NCBI_FIX_DIR(APACHE_ARROW_PATH)
         break
      fi
   done
fi

NCBI_CHECK_THIRD_PARTY_LIB_EX(apache_arrow, APACHE_ARROW, parquet,
  [AC_LANG_PROGRAM([[@%:@include <parquet/api/reader.h>]],
     [[parquet::ParquetFileReader pfr;]])],
  [-larrow])
if test "$with_apache_arrow" != no -a \
     -f "$APACHE_ARROW_LIBDIR/libparquet-static.a"; then
    APACHE_ARROW_STATIC_LIBS="-L$APACHE_ARROW_LIBDIR -lparquet-static -larrow-static -larrow_bundled_dependencies-static $BZ2_LIBS $Z_LIBS -lzstd"
else
    APACHE_ARROW_STATIC_LIBS=$APACHE_ARROW_LIBS
fi

case "$with_librdkafka" in
   yes | no | '' ) ;;
   *             ) LIBRDKAFKA_PATH=$with_librdkafka ;;
esac
if test -d "$LIBRDKAFKA_PATH"; then
   NCBI_FIND_ARCH_PATH(LIBRDKAFKA)
   LIBRDKAFKA_PATH=$LIBRDKAFKA_ARCH_PATH
   NCBI_FIX_DIR(LIBRDKAFKA_PATH)
fi

NCBI_CHECK_THIRD_PARTY_LIB_EX(librdkafka, LIBRDKAFKA, rdkafka,
  [AC_LANG_PROGRAM([[@%:@include <librdkafka/rdkafka.h>]],
      [[rd_kafka_conf_t *conf = rd_kafka_conf_new();]])])
if test "$with_librdkafka" != no -a \
     -f "$LIBRDKAFKA_PATH/lib$bit64_sfx/librdkafka-static.a"; then
   LIBRDKAFKA_STATIC_LIBS="-L$LIBRDKAFKA_PATH/lib$bit64_sfx -lrdkafka-static"
else
   LIBRDKAFKA_STATIC_LIBS=$LIBRDKAFKA_LIBS
fi

case "$with_cppkafka" in
   yes | no | '' ) ;;
   *             ) CPPKAFKA_PATH=$with_cppkafka ;;
esac
if test -d "$CPPKAFKA_PATH"; then
   NCBI_FIND_ARCH_PATH(CPPKAFKA)
   CPPKAFKA_PATH=$CPPKAFKA_ARCH_PATH
   if test -d "$CPPKAFKA_PATH$asan_sfx"; then
      CPPKAFKA_PATH="$CPPKAFKA_PATH$asan_sfx"
   fi
   NCBI_FIX_DIR(CPPKAFKA_PATH)
fi

NCBI_CHECK_THIRD_PARTY_LIB(cppkafka,
  [AC_LANG_PROGRAM([[@%:@include <cppkafka/configuration.h>]],
      [[cppkafka::Configuration cfg; cfg.set("foo", "bar");]])],
  [$LIBRDKAFKA_LIBS], [], [$BOOST_INCLUDE $LIBRDKAFKA_INCLUDE])
if test "$with_cppkafka" != no -a \
     -f "$CPPKAFKA_PATH/lib$bit64_sfx/libcppkafka-static.a"; then
   CPPKAFKA_STATIC_LIBS="-L$CPPKAFKA_PATH/lib$bit64_sfx -lcppkafka-static $LIBRDKAFKA_STATIC_LIBS"
else
   CPPKAFKA_STATIC_LIBS=$CPPKAFKA_LIBS
fi


case "$with_thrift" in
   yes | no | '' ) ;;
   *             ) THRIFT_PATH=$with_thrift ;;
esac
if test -d "$THRIFT_PATH"; then
   NCBI_FIND_ARCH_PATH(THRIFT)
   THRIFT_PATH=$THRIFT_ARCH_PATH
   if test -d "$THRIFT_PATH$asan_sfx"; then
      THRIFT_PATH="$THRIFT_PATH$asan_sfx"
   fi
   NCBI_FIX_DIR(THRIFT_PATH)
fi

if test -n "$D_SFX"; then
   if ls $THRIFT_PATH/lib*/libthrift$D_SFX.* >/dev/null 2>&1; then
      THRIFT_SFX=$D_SFX
   else
      for ext in .a .so .dylib; do
         path=`$CXX -B$THRIFT_PATH/ -print-file-name=libthrift$D_SFX.$ext \
               2>/dev/null`
         case "$path" in
            */* ) THRIFT_SFX=$D_SFX; break ;;
         esac
      done
   fi
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(thrift, THRIFT, [thrift$THRIFT_SFX],
  [AC_LANG_PROGRAM([[@%:@include <thrift/TApplicationException.h>]],
      [[apache::thrift::TApplicationException().read(nullptr);]])],
  [], [$OPENSSL_LIBS], [$BOOST_INCLUDE])
if test "$with_thrift" != no -a \
   \( -f "$THRIFT_PATH/lib/libthrift${THRIFT_SFX}_static.a" \
   -o -f "$THRIFT_PATH/lib/libthrift_static$THRIFT_SFX.a" \); then
   if test -f "$THRIFT_PATH/lib/libthrift${THRIFT_SFX}_static.a"; then
      THRIFT_STATIC_LIBS="-L$THRIFT_PATH/lib -lthrift${THRIFT_SFX}_static"
   else
      THRIFT_STATIC_LIBS="-L$THRIFT_PATH/lib -lthrift_static$THRIFT_SFX"
   fi
fi


case "$with_nlohmann_json" in
   yes | no | '' ) ;;
   *             ) NLOHMANN_JSON_PATH=$with_nlohmann_json ;;
esac
if test "$with_nlohmann_json" != no; then
   in_nlohmann_json=
   if test -d "$NLOHMANN_JSON_PATH"; then
      NCBI_FIX_DIR(NLOHMANN_JSON_PATH)
      in_nlohmann_json=" in $NLOHMANN_JSON_PATH"
   fi
   NLOHMANN_JSON_INCLUDE=-I$NLOHMANN_JSON_PATH/include
   AC_CACHE_CHECK([for JSON for Modern C++$in_nlohmann_json],
      ncbi_cv_lib_nlohmann_json,
      [CPPFLAGS="$NLOHMANN_JSON_INCLUDE $orig_CPPFLAGS"
       AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM([[@%:@include <nlohmann/json.hpp>]],
                           [[nlohmann::json j; j["foo"] = "bar";]])],
          [ncbi_cv_lib_nlohmann_json=yes], [ncbi_cv_lib_nlohmann_json=no])])
    if test "$ncbi_cv_lib_nlohmann_json" = yes; then
       NCBI_PACKAGE(NLohmann_JSON)
    else
       NCBI_MISSING_PACKAGE(nlohmann-json)
       NLOHMANN_JSON_INCLUDE=
    fi
fi


case "$with_yaml_cpp" in
   yes | no | '' ) ;;
   *             ) YAML_CPP_PATH=$with_yaml_cpp ;;
esac
if test -d "$YAML_CPP_PATH"; then
   NCBI_FIND_ARCH_PATH(YAML_CPP)
   YAML_CPP_PATH=$YAML_CPP_ARCH_PATH
   NCBI_FIX_DIR(YAML_CPP_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(yaml_cpp, YAML_CPP, yaml-cpp,
  [AC_LANG_PROGRAM([[@%:@include <yaml-cpp/yaml.h>]],
      [[YAML::Node n; YAML::Dump(n);]])])
if test "$with_yaml_cpp" != no -a -f "$YAML_CPP_PATH/lib/libyaml-cpp-static.a"
then
   YAML_CPP_STATIC_LIBS="-L$YAML_CPP_PATH/lib -lyaml-cpp-static"
fi


case "$with_opentracing" in
   yes | no | '' ) ;;
   *             ) OPENTRACING_PATH=$with_opentracing ;;
esac
if test -d "$OPENTRACING_PATH"; then
   NCBI_FIND_ARCH_PATH(OPENTRACING)
   OPENTRACING_PATH=$OPENTRACING_ARCH_PATH
   NCBI_FIX_DIR(OPENTRACING_PATH)
fi
NCBI_CHECK_THIRD_PARTY_LIB(opentracing,
  [AC_LANG_PROGRAM([[@%:@include <opentracing/tracer_factory.h>]],
      [[opentracing::tracer_factory_error_category();]])])
if test "$with_opentracing" != no \
   -a -f "$OPENTRACING_PATH/lib/libopentracing-static.a"; then
   OPENTRACING_STATIC_LIBS="-L$OPENTRACING_PATH/lib -lopentracing-static"
fi


case "$with_jaeger" in
   yes | no | '' ) ;;
   *             ) JAEGER_PATH=$with_jaeger ;;
esac
if test -d "$JAEGER_PATH"; then
   NCBI_FIND_ARCH_PATH(JAEGER)
   JAEGER_PATH=$JAEGER_ARCH_PATH
   if test -d "$JAEGER_PATH$asan_sfx"; then
      JAEGER_PATH="$JAEGER_PATH$asan_sfx"
   fi
   NCBI_FIX_DIR(JAEGER_PATH)
fi
if test -d $JAEGER_PATH/lib${bit64_sfx}; then
   JAEGER_LIBDIR=$JAEGER_PATH/lib${bit64_sfx}
else
   JAEGER_LIBDIR=$JAEGER_PATH/lib
fi
NCBI_CHECK_THIRD_PARTY_LIB_EX(jaeger, JAEGER, jaegertracing,
  [AC_LANG_PROGRAM([[@%:@include <jaegertracing/Tracer.h>]],
      [[jaegertracing::SelfRef(nullptr);]])],
  [$OPENTRACING_LIBS $YAML_CPP_LIBS $THRIFT_LIBS], [$OPENSSL_LIBS],
  [$OPENTRACING_INCLUDE $YAML_CPP_INCLUDE $NLOHMANN_JSON_INCLUDE $THRIFT_INCLUDE])
if test "$with_jaeger" != no \
   -a -f "$JAEGER_PATH/lib/libjaegertracing-static.a"; then
   JAEGER_STATIC_LIBS="-L$JAEGER_PATH/lib -ljaegertracing-static"
   JAEGER_STATIC_LIBS="$JAEGER_STATIC_LIBS $OPENTRACING_STATIC_LIBS"
   JAEGER_STATIC_LIBS="$JAEGER_STATIC_LIBS $YAML_CPP_STATIC_LIBS"
   JAEGER_STATIC_LIBS="$JAEGER_STATIC_LIBS $THRIFT_STATIC_LIBS"
fi


### Restore original compiler/linker flags
LIBS="$orig_LIBS"
CPPFLAGS="$orig_CPPFLAGS"


### Optional projects
### --------------------------------------------


## `connext' support

AC_DEFINE(HAVE_LIBCONNEXT, 1,
   [Define to 1 if historically non-public CONNECT extensions are available.])


## direct PubSeqOS data loaders

if test "$with_dbapi" != no -a \
   -f ${real_srcdir}/src/objtools/data_loaders/genbank/pubseq/Makefile.ncbi_xreader_pubseqos.lib ; then
   AC_DEFINE(HAVE_PUBSEQ_OS, 1,
      [Define to 1 if the PUBSEQ service is available.])
   NCBI_FEATURE(PubSeqOS)
   ncbi_xreader_pubseqos=ncbi_xreader_pubseqos
   ncbi_xreader_pubseqos2=ncbi_xreader_pubseqos2
   UNLESS_PUBSEQOS=\#
else
   ncbi_xreader_pubseqos=
   ncbi_xreader_pubseqos2=
   UNLESS_PUBSEQOS=
fi


## `serial' projects

if test "$with_serial" = "no" ; then
   serial=
else
   NCBI_PROJECT(serial)
   serial="serial"
fi


## `objects' projects

if test "$with_objects" = "no"  -o  -z "$serial" ; then
   objects=
else
   NCBI_PROJECT(objects)
   objects="objects"
fi


## PSG loader

reason=
sep=
if test "$with_mt" = no; then
   reason=MT
   sep=", "
fi
if test "$with_libuv" = no; then
   reason="${reason}${sep}LIBUV"
   sep=", "
fi
if test "$with_nghttp2" = no; then
   reason="${reason}${sep}NGHTTP2"
   sep=", "
fi
if test -z "$reason"; then
   AC_DEFINE(HAVE_PSG_LOADER, 1,
      [Define to 1 to let the GenBank data loader use PubSeq Gateway.])
   NCBI_FEATURE(PSGLoader)
else
   case " $with_experimental " in
      *\ PSGLoader\ * )
         AC_MSG_ERROR([--with-experimental=$with_experimental: Cannot build PSG loader: missing $missing])
         ;;
   esac
fi


## `bdb' projects

dnl NCBI_CHECK_SUBTREE(bdb)
if test "$with_bdb" = "no" ; then
   NoConfProjects="$NoConfProjects bdb"
fi

if test ! -f ${real_srcdir}/src/db/bdb/Makefile.in  -o  \
        ! -d ${real_srcdir}/include/db/bdb ; then
   if test "${with_bdb-no}" != "no" ; then
      AC_MSG_ERROR([--with-]bdb[:  ]BDB[ sources are missing])
   fi
   with_bdb="no"
fi


if test "$with_bdb" = "no" ; then
   bdb=
   BDB_LIB=
   BDB_CACHE_LIB=
else
   NCBI_PROJECT(bdb)
   bdb="bdb"
   BDB_LIB="bdb"
   AC_DEFINE(HAVE_BDB, 1,
             [Define to 1 if NCBI C++ API for BerkeleyDB is available.])
   bdb_cache="ncbi_xcache_bdb"
   BDB_CACHE_LIB="ncbi_xcache_bdb"
   AC_DEFINE(HAVE_BDB_CACHE, 1,
             [Define to 1 if NCBI C++ API for BerkeleyDB based data cache is available.])
fi


## `dbapi' projects

DBAPI_DRIVER=
DBAPI_CTLIB=
DBAPI_FTDS=
DBAPI_FTDS100=
DBAPI_MYSQL=
DBAPI_ODBC=
if test "$with_dbapi" = "no" ; then
   dbapi=
else
   NCBI_PROJECT(dbapi)
   dbapi="dbapi"
   DBAPI_DRIVER=dbapi_driver
   DBAPI_FTDS=ncbi_xdbapi_ftds
   DBAPI_FTDS100=ncbi_xdbapi_ftds100
   test -n "$SYBASE_LIBS"    &&  DBAPI_CTLIB=ncbi_xdbapi_ctlib
   test -n "$MYSQL_LIBS"     &&  DBAPI_MYSQL=ncbi_xdbapi_mysql
   test -n "$ODBC_LIBS"      &&  DBAPI_ODBC=ncbi_xdbapi_odbc
fi


## `app' projects

if test "$with_app" = "no" ; then
   app=
else
   NCBI_PROJECT(app)
   app="app"
fi


## `ctools' project cluster

if test "$with_ctools" != "no" ; then
   NCBI_PROJECT(ctools)
fi


## `gui' projects

if test "$with_gui" = "no" ; then
   gui=
else
   NCBI_PROJECT(gui)
   gui="gui"
fi


## `algo' projects

if test "$with_algo" = "no" -o -z "$objects" ; then
   algo=
else
   NCBI_PROJECT(algo)
   algo="algo"
fi


## `internal' project cluster

if test "$with_internal" = "no"  \
    -o  ! -f "${real_srcdir}/src/internal/Makefile.in"; then
   NoConfProjects="$NoConfProjects internal"
   internal=
else
   reason=""
   sep=
   if test ! -d "${real_srcdir}/include/internal"; then
     reason="$reason${sep}headers"
     sep=", "
   fi
   if test "$with_sybase" = "no"; then
     reason="$reason${sep}Sybase"
     sep=", "
   fi
   if test "$with_ncbi_c" = "no"; then
     reason="$reason${sep}C-Toolkit"
     sep=", "
   fi
   if test "$with_sss" = "no"; then
     reason="$reason${sep}SSS"
     sep=", "
   fi
   if test -n "$reason" -a "$with_internal" = "yes"; then
      if test -z "$with_projects"; then
         AC_MSG_ERROR([--with-internal:  Cannot build INTERNAL projects: missing $reason])
      else
         AC_MSG_WARN([--with-internal:  Cannot build some INTERNAL projects: missing $reason])
         OPT_GROUPS="$OPT_GROUPS internal"
         internal="internal"
      fi
   elif test -n "$reason" -a -z "$with_projects"; then
      NoConfProjects="$NoConfProjects internal"
      internal=
   else
      OPT_GROUPS="$OPT_GROUPS internal"
      internal="internal"
   fi
fi

## Genome Workbench

if test "$with_gbench" != "no"  -a  -d "$real_srcdir/src/app/gbench"; then
   reason=""
   sep=
   if test "$with_wxwidgets" = "no"; then
     reason="$reason${sep}wxWidgets"
     sep=", "
   fi
   if test ! -d "$real_srcdir/src/gui/packages"; then
     reason="$reason${sep}internal packages"
     sep=", "
   fi
   if test "$with_opengl" = "no"; then
     reason="$reason${sep}OpenGL"
     sep=", "
   fi
   if test "$with_glew" = "no"; then
     reason="$reason${sep}GLEW"
     sep=", "
   fi
   if test "$with_ftgl" = "no"; then
     reason="$reason${sep}FTGL"
     sep=", "
   fi
   if test "$with_sqlite3" = "no"; then
     reason="$reason${sep}SQLite 3.x"
     sep=", "
   fi
   if test "$with_bdb" = "no"; then
     reason="$reason${sep}Berkeley DB"
     sep=", "
   fi
   if test "$ncbi_cv_lib_boost_spirit" != "yes"; then
     reason=Boost.Spirit
     sep=", "
   fi
   if test "$with_libxslt" = "no"; then
     reason="$reason${sep}libxslt"
     sep=", "
   fi
   if test "$with_mt" = "no"; then
     reason="$reason${sep}multithreading"
     sep=", "
   fi
   if test "$with_dll" != "yes"; then
     reason="$reason${sep}full-DLL setup"
     sep=", "
   fi
   if test "$with_algo" = "no"; then
     reason="$reason${sep}other required subtrees"
     sep=","
   fi
   # Anything else?
   if test -n "$reason" -a "$with_gbench" = "yes"; then
      AC_MSG_ERROR([--with-gbench:  Cannot build Genome Workbench: missing $reason])
   elif test -z "$reason"; then
      NCBI_PROJECT(gbench)
   fi
fi



### Miscellanea
### --------------------------------------------

if test "$with_execopy" = "no" ; then
   APP_NOCOPY="BINCOPY=@:"
else
   APP_NOCOPY=
fi

if test "$with_exe" = "no" ; then
   APP_OR_NULL=null
else
   APP_OR_NULL=app
fi

IF_REBUILDING_LIBS="#"
IF_REBUILDING_CONDITIONALLY="#"
case "$with_lib_rebuilds" in
  yes) IF_REBUILDING_LIBS="" ;;
  ask) IF_REBUILDING_CONDITIONALLY="" ;;
esac

case "$with_deactivation" in
  no) IF_DEACTIVATING="#" ;;
  * ) IF_DEACTIVATING=""  ;;
esac

case "$with_makefile_auto_update" in
  no) configurables_mfname=configurables.null ;;
  * ) configurables_mfname=configurables      ;;
esac

# Run the test suite after the build?

if test -n "$with_check"  -a  "$with_check" != "no" ; then
   check="check"
   if test "$with_check" != "yes" ; then
      CHECK_ARG=`echo "$with_check" | sed 's/%/ /g'`
   fi
   NCBI_FEATURE(check)
fi
CHECK_TOOLS=$with_check_tools
case "$CHECK_TOOLS" in
   [*[Vv][Aa][Ll][Gg][Rr][Ii][Nn][Dd]*] ) NCBI_FEATURE(Valgrind) ;;
   [*[Hh][Ee][Ll][Gg][Rr][Ii][Nn][Dd]*] ) NCBI_FEATURE(Valgrind) ;;
esac
CHECK_OS_NAME=
: ${CHECK_TIMEOUT_MULT=1}
case "$host_os" in
   linux* )
      if test -x /usr/bin/lsb_release; then
         CHECK_OS_NAME=`lsb_release -is | tr A-Z a-z`
      elif test -r /etc/SuSE-release; then
         CHECK_OS_NAME=suse
      elif test -r /etc/redhat-release; then
         CHECK_OS_NAME=`cut -d' ' -f1 /etc/redhat-release | tr A-Z a-z`
      elif test -d /usr/share/doc/ubuntu-keyring; then
         CHECK_OS_NAME=ubuntu
      fi
      ;;
esac

if test "${with_limited_linker}" = "yes"; then
   NCBI_FEATURE(LimitedLinker)
fi

if test "${with_skew_guard-$with_ncbi_public}" = "yes"; then
    AC_DEFINE(HAVE_NCBI_SKEW_GUARD, 1,
       [Define to 1 to catch incomplete rebuilds.])
fi

FEATURES="$WithFeatures $WithPackages $WithProjects"

### Compute Without{Features,Packages,Projects}.  Takes quadratic time,
### but that's life.
m4_foreach(CATEGORY, [Features,Packages,Projects],
  [for x in m4_indir([NCBI_ALL_]CATEGORY); do
      case " [$With]CATEGORY " in
         *" $x "*) ;;
         *) [Without]CATEGORY="[$Without]CATEGORY[$Without]CATEGORY[Sep$x]"
            [Without]CATEGORY[Sep]=" "
            FEATURES="$FEATURES -$x"
          ;;
      esac
   done
  ])
# Sort, then consolidate back to a single line
FEATURES=`echo $FEATURES | fmt -w1 | sort -dfu`
FEATURES=`echo $FEATURES`


### Get rid of the KCC "anti-license-warning" filter
if test "$KCC" = "yes"  -a  -n "$kcc_license" ; then
   CC="$kcc_CC"
   CXXCPP="$kcc_CXX -E"
   CXX="$kcc_CXX"
fi

### Get rid of the ICC "anti-license-warning" filter
if test "$ICC" = "yes"  -a  -n "$icc_license" ; then
   CC="$icc_CC"
   CXXCPP="$icc_CXX -E"
   CXX="$icc_CXX"
fi

### Adjust paths to wrapper.*.sh
case "$CC"     in compilers/*)     CC="\$(top_srcdir)/$CC"     ;; esac
case "$CXX"    in compilers/*)    CXX="\$(top_srcdir)/$CXX"    ;; esac
case "$CXXCPP" in compilers/*) CXXCPP="\$(top_srcdir)/$CXXCPP" ;; esac
case "$AR"     in compilers/*)     AR="\$(top_srcdir)/$AR"     ;; esac

### Get Insure++ to honor the Toolkit's psrc file
case "$CC" in
   */insure*)
      CC="$CC -Zop \$(top_srcdir)/compilers/unix/psrc -D__INSURE__"
      CXX="$CXX -Zop \$(top_srcdir)/compilers/unix/psrc -D__INSURE__"
      CXXCPP="$CXXCPP -Zop \$(top_srcdir)/compilers/unix/psrc -D__INSURE__"
      LINK_DLL=`echo "$LINK_DLL" | sed -e 's:insure:& -Zop \$(top_srcdir)/compilers/unix/psrc:'`
   ;;
esac


#############################################################################
### Compose a list of configurables("*.in" -- makefiles, shell scripts, etc.)
### in subdirs to configure
### Compose their target counterparts
### Configure

AC_MSG_NOTICE([looking for configurables below $real_srcdir...])
tmp_sed="`pwd`/config.tmp.$$"
for x in $NoConfProjects dll; do
   echo "/^\\.\\/$x/d"
done > $tmp_sed
cat >>$tmp_sed <<EOF
s%^.\\(/build-system.*/Makefile*\\)\\.in\$%$builddir\\1:./src\\1\\.in%
s%^.\\(/build-system\\)\\(/.*\\)\\.in\$%$builddir\\2:./src\\1\\2\\.in%
s%^.\\(/[[^:]]*\\)\\.in\$%$builddir\\1:./src\\1\\.in%
EOF
cat $tmp_sed >&AS_MESSAGE_LOG_FD
configurables=`cd "${real_srcdir}/src"  &&  find . -name '.svn' -prune -o -name '*.in' -print | sed -f $tmp_sed`
rm $tmp_sed

if test -z "$configurables" ; then
  AC_MSG_ERROR([cannot find any configurables below "${real_srcdir}"!])
else
  AC_MSG_NOTICE([...done])
fi

ncbi_runpath=`eval echo "$pure_runpath"`
dnl AC_DEFINE_UNQUOTED(NCBI_RUNPATH, "$ncbi_runpath", [NCBI runpath])
c_ncbi_runpath=`echo "$ncbi_runpath" | sed -e 's:\\$\\$:\\$:g'`

### Template substitutions
AC_SUBST(signature)

AC_SUBST(build_root)

AC_SUBST(top_srcdir)
AC_SUBST(srcdir)
#AC_SUBST(real_srcdir)
AC_SUBST(includedir)
AC_SUBST(status_dir)
AC_SUBST(builddir)
AC_SUBST(runpath)
AC_SUBST(ncbi_runpath)
AC_SUBST(c_ncbi_runpath)

AC_SUBST(CC)
AC_SUBST(CPP)
AC_SUBST(CXX)
AC_SUBST(AR)
AC_SUBST(RANLIB)
AC_SUBST(STRIP)
AC_SUBST(LINK)
AC_SUBST(C_LINK)
AC_SUBST(TAIL_N)
AC_SUBST(EGREP_Q)
AC_SUBST(LDD_R)

AC_SUBST(CFLAGS)
AC_SUBST(FAST_CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(FAST_CXXFLAGS)
AC_SUBST(OBJCXX_CXXFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(DEPFLAGS)
AC_SUBST(DEPFLAGS_POST)
AC_SUBST(LDFLAGS)
AC_SUBST(FAST_LDFLAGS)
AC_SUBST(APP_LDFLAGS)
AC_SUBST(DLL_LDFLAGS)
AC_SUBST(LIBS)
AC_SUBST(C_LIBS)
AC_SUBST(OBJCXX_LIBS)
AC_SUBST(FOUNDATION_LIBS)
AC_SUBST(GCCPCH)
AC_SUBST(RUNPATH_ORIGIN)
AC_SUBST(NO_STRICT_ALIASING)

AC_SUBST(D_SFX)
AC_SUBST(DEBUG_SFX)

AC_SUBST(LIB_OR_DLL)
AC_SUBST(FORCE_STATIC_LIB)
AC_SUBST(APP_LIB_SETTING)
AC_SUBST(APP_LIBS_SETTING)
AC_SUBST(LINK_DLL)
AC_SUBST(has_dll_loadable)
AC_SUBST(LINK_LOADABLE)
AC_SUBST(CFLAGS_DLL)
AC_SUBST(CXXFLAGS_DLL)
AC_SUBST(ALLOW_UNDEF)
AC_SUBST(FORBID_UNDEF)
AC_SUBST(AS_NEEDED)
AC_SUBST(NO_AS_NEEDED)
AC_SUBST(WHOLE_ARCHIVE)
AC_SUBST(NO_WHOLE_ARCHIVE)

AC_SUBST(OPT_GROUPS)
AC_SUBST(CONNEXT)
AC_SUBST(XCONNEXT)
AC_SUBST(serial)
AC_SUBST(bdb)
AC_SUBST(dbapi)
AC_SUBST(objects)
AC_SUBST(gui)
AC_SUBST(algo)
AC_SUBST(app)
AC_SUBST(internal)

AC_SUBST(check)
AC_SUBST(CHECK_ARG)
AC_SUBST(CHECK_TOOLS)
AC_SUBST(CHECK_TIMEOUT_MULT)
AC_SUBST(CHECK_OS_NAME)
AC_SUBST(FEATURES)

AC_SUBST(script_shell)
AC_SUBST(make_shell)
AC_SUBST(obj_ext)
AC_SUBST(lib_pre)
AC_SUBST(lib_l_pre)
AC_SUBST(lib_ext)
AC_SUBST(dll_ext)
AC_SUBST(loadable_ext)
AC_SUBST(lib_l_ext)
AC_SUBST(exe_ext)
AC_SUBST(f_compile)
AC_SUBST(f_outobj)
AC_SUBST(f_outlib)
AC_SUBST(f_libpath)
AC_SUBST(f_runpath)
AC_SUBST(f_outexe)

AC_SUBST(BDB_LIB)
AC_SUBST(BDB_CACHE_LIB)
AC_SUBST(SQLITE3_WRAPPER)
AC_SUBST(DBAPI_DRIVER)
AC_SUBST(DBAPI_CTLIB)
AC_SUBST(DBAPI_FTDS)
AC_SUBST(DBAPI_FTDS100)
AC_SUBST(DBAPI_MYSQL)
AC_SUBST(DBAPI_ODBC)

AC_SUBST(THREAD_LIBS)
AC_SUBST(NCBIATOMIC_LIB)
AC_SUBST(OPENMP_FLAGS)
AC_SUBST(UNSAFE_MATH_FLAG)
AC_SUBST(SSE4_1_FLAG)
AC_SUBST(AES_FLAG)
AC_SUBST(COLOR_DIAGNOSTICS)
AC_SUBST(NETWORK_LIBS)
AC_SUBST(NETWORK_PURE_LIBS)
AC_SUBST(RESOLVER_LIBS)
AC_SUBST(MATH_LIBS)
AC_SUBST(KSTAT_LIBS)
AC_SUBST(RPCSVC_LIBS)
AC_SUBST(CRYPT_LIBS)
AC_SUBST(DL_LIBS)
AC_SUBST(RT_LIBS)
AC_SUBST(UUID_LIBS)
AC_SUBST(DEMANGLE_LIBS)
AC_SUBST(ICONV_LIBS)
AC_SUBST(Z_LIB)
AC_SUBST(BZ2_LIB)
AC_SUBST(ZSTD_STATIC_LIBS)
AC_SUBST(PCREPOSIX_LIBS)
AC_SUBST(PCRE_LIB)
AC_SUBST(OPENSSL_STATIC_LIBS)
AC_SUBST(CURL_STATIC_LIBS)
AC_SUBST(SYBASE_PATH)
AC_SUBST(SYBASE_LCL_PATH)
AC_SUBST(SYBASE_INCLUDE)
AC_SUBST(SYBASE_LIBS)
AC_SUBST(SYBASE_DLLS)
AC_SUBST(SYBASE_DBLIBS)
AC_SUBST(MYSQL_INCLUDE)
AC_SUBST(MYSQL_LIBS)
AC_SUBST(BERKELEYDB_INCLUDE)
AC_SUBST(BERKELEYDB_LIBS)
AC_SUBST(BERKELEYDB_STATIC_LIBS)
AC_SUBST(BERKELEYDB_CXX_LIBS)
AC_SUBST(BERKELEYDB_CXX_STATIC_LIBS)
AC_SUBST(ODBC_INCLUDE)
AC_SUBST(ODBC_LIBS)
AC_SUBST(BOOST_INCLUDE)
AC_SUBST(BOOST_LIBPATH)
AC_SUBST(BOOST_TAG)
AC_SUBST(BOOST_STATIC_TAG)
AC_SUBST(BOOST_CHRONO_LIBS)
AC_SUBST(BOOST_CHRONO_STATIC_LIBS)
AC_SUBST(BOOST_FILESYSTEM_LIBS)
AC_SUBST(BOOST_FILESYSTEM_STATIC_LIBS)
AC_SUBST(BOOST_IOSTREAMS_LIBS)
AC_SUBST(BOOST_IOSTREAMS_STATIC_LIBS)
AC_SUBST(BOOST_PROGRAM_OPTIONS_LIBS)
AC_SUBST(BOOST_PROGRAM_OPTIONS_STATIC_LIBS)
AC_SUBST(BOOST_REGEX_LIBS)
AC_SUBST(BOOST_REGEX_STATIC_LIBS)
AC_SUBST(BOOST_SERIALIZATION_LIBS)
AC_SUBST(BOOST_SERIALIZATION_STATIC_LIBS)
AC_SUBST(BOOST_SYSTEM_LIBS)
AC_SUBST(BOOST_SYSTEM_STATIC_LIBS)
AC_SUBST(BOOST_TEST_PEM_LIBS)
AC_SUBST(BOOST_TEST_PEM_STATIC_LIBS)
AC_SUBST(BOOST_TEST_TEM_LIBS)
AC_SUBST(BOOST_TEST_TEM_STATIC_LIBS)
AC_SUBST(BOOST_TEST_UTF_LIBS)
AC_SUBST(BOOST_TEST_UTF_STATIC_LIBS)
AC_SUBST(BOOST_THREAD_LIBS)
AC_SUBST(BOOST_THREAD_STATIC_LIBS)
AC_SUBST(NCBI_C_INCLUDE)
AC_SUBST(NCBI_C_LIBPATH)
AC_SUBST(OPENGL_INCLUDE)
AC_SUBST(OPENGL_LIBS)
AC_SUBST(OPENGL_STATIC_LIBS)
AC_SUBST(OSMESA_INCLUDE)
AC_SUBST(OSMESA_LIBS)
AC_SUBST(OSMESA_STATIC_LIBS)
AC_SUBST(GLUT_INCLUDE)
AC_SUBST(GLUT_LIBS)
AC_SUBST(GLEW_INCLUDE)
AC_SUBST(GLEW_LIBS)
AC_SUBST(GLEW_STATIC_LIBS)
AC_SUBST(GL2PS_INCLUDE)
AC_SUBST(GL2PS_LIBS)
AC_SUBST(GL2PS_STATIC_LIBS)
AC_SUBST(WXWIDGETS_INCLUDE)
AC_SUBST(WXWIDGETS_LIBS)
AC_SUBST(WXWIDGETS_STATIC_LIBS)
AC_SUBST(WXWIDGETS_GL_LIBS)
AC_SUBST(WXWIDGETS_GL_STATIC_LIBS)
AC_SUBST(WXWIDGETS_POST_LINK)
AC_SUBST(FASTCGI_INCLUDE)
AC_SUBST(FASTCGI_LIBS)
AC_SUBST(FASTCGI_OBJS)
AC_SUBST(NCBI_SSS_INCLUDE)
AC_SUBST(NCBI_SSS_LIBPATH)
AC_SUBST(LIBSSSUTILS)
AC_SUBST(LIBSSSDB)
AC_SUBST(sssutils)
AC_SUBST(VDB_INCLUDE)
AC_SUBST(VDB_LIBS)
AC_SUBST(VDB_STATIC_LIBS)
AC_SUBST(bamread)
AC_SUBST(sraread)
AC_SUBST(ncbi_id2proc_snp)
AC_SUBST(ncbi_id2proc_wgs)
AC_SUBST(ncbi_xloader_bam)
AC_SUBST(ncbi_xloader_csra)
AC_SUBST(ncbi_xloader_snp)
AC_SUBST(ncbi_xloader_sra)
AC_SUBST(ncbi_xloader_vdbgraph)
AC_SUBST(ncbi_xloader_wgs)
AC_SUBST(VDB_REQ)
AC_SUBST(VDB_POST_LINK)
AC_SUBST(NGS_STATIC_LIBS)
AC_SUBST(SP_INCLUDE)
AC_SUBST(SP_LIBS)
AC_SUBST(ORBACUS_INCLUDE)
AC_SUBST(ORBACUS_LIBPATH)
AC_SUBST(LIBOB)
AC_SUBST(LIBIMR)
AC_SUBST(ICU_CONFIG)
AC_SUBST(ICU_INCLUDE)
AC_SUBST(ICU_LIBS)
AC_SUBST(ICU_STATIC_LIBS)
AC_SUBST(EXPAT_STATIC_LIBS)
AC_SUBST(SABLOT_STATIC_LIBS)
AC_SUBST(LIBXML_STATIC_LIBS)
AC_SUBST(LIBXSLT_STATIC_LIBS)
AC_SUBST(LIBEXSLT_STATIC_LIBS)
AC_SUBST(XERCES_INCLUDE)
AC_SUBST(XERCES_LIBS)
AC_SUBST(XERCES_STATIC_LIBS)
AC_SUBST(XALAN_INCLUDE)
AC_SUBST(XALAN_LIBS)
AC_SUBST(XALAN_STATIC_LIBS)
AC_SUBST(ZORBA_INCLUDE)
AC_SUBST(ZORBA_LIBS)
AC_SUBST(ZORBA_STATIC_LIBS)
AC_SUBST(SQLITE3_STATIC_LIBS)
AC_SUBST(FREETYPE_INCLUDE)
AC_SUBST(FREETYPE_LIBS)
AC_SUBST(GSOAP_PATH)
AC_SUBST(AVRO_STATIC_LIBS)
AC_SUBST(CEREAL_INCLUDE)
AC_SUBST(MONGODB_STATIC_LIBS)
AC_SUBST(MONGODB3_STATIC_LIBS)
AC_SUBST(GMOCK_STATIC_LIBS)
AC_SUBST(LMDB_LIB)
AC_SUBST(LMDB_STATIC_LIBS)
AC_SUBST(LIBUV_STATIC_LIBS)
AC_SUBST(LIBSSH2_STATIC_LIBS)
AC_SUBST(CASSANDRA_STATIC_LIBS)
AC_SUBST(NGHTTP2_STATIC_LIBS)
AC_SUBST(H2O_STATIC_LIBS)
AC_SUBST(INFLUXDB_INCLUDE)
AC_SUBST(LIBXLSXWRITER_STATIC_LIBS)
AC_SUBST(PROTOC)
AC_SUBST(PROTOBUF_BIN)
AC_SUBST(GRPC_UNSECURE_LIBS)
AC_SUBST(GRPC_REFLECTION_LIBS)
AC_SUBST(GRPC_CPP_PLUGIN)
AC_SUBST(GRPC_BIN)
AC_SUBST(MSGSL_INCLUDE)
AC_SUBST(AWS_SDK_STATIC_LIBS)
AC_SUBST(CRC32C_STATIC_LIBS)
AC_SUBST(HIREDIS_STATIC_LIBS)
AC_SUBST(APACHE_ARROW_STATIC_LIBS)
AC_SUBST(LIBRDKAFKA_STATIC_LIBS)
AC_SUBST(CPPKAFKA_STATIC_LIBS)
AC_SUBST(THRIFT_STATIC_LIBS)
AC_SUBST(NLOHMANN_JSON_INCLUDE)
AC_SUBST(YAML_CPP_STATIC_LIBS)
AC_SUBST(OPENTRACING_STATIC_LIBS)
AC_SUBST(JAEGER_STATIC_LIBS)
AC_SUBST(ncbi_xreader_pubseqos)
AC_SUBST(ncbi_xreader_pubseqos2)
AC_SUBST(UNLESS_PUBSEQOS)
AC_SUBST(PERL)
AC_SUBST(PERL_INCLUDE)
AC_SUBST(PERL_LIBS)
AC_SUBST(JDK_PATH)
AC_SUBST(JDK_INCLUDE)
AC_SUBST(ncbi_java)

AC_SUBST(NCBI_C_ncbi)

AC_SUBST(BINCOPY)
AC_SUBST(APP_NOCOPY)
AC_SUBST(APP_OR_NULL)
AC_SUBST(IF_REBUILDING_LIBS)
AC_SUBST(IF_REBUILDING_CONDITIONALLY)
AC_SUBST(IF_DEACTIVATING)
AC_SUBST(configurables_mfname)
AC_SUBST(CC_FILTER)
AC_SUBST(CXX_FILTER)
AC_SUBST(AR_FILTER)
AC_SUBST(LINK_FILTER)
AC_SUBST(CC_WRAPPER)
AC_SUBST(CXX_WRAPPER)
AC_SUBST(AR_WRAPPER)
AC_SUBST(LINK_WRAPPER)

AC_SUBST(KeepStateTarget)
AC_SUBST(Rules)
AC_SUBST(serial_ws50_rtti_kludge)
AC_SUBST(ncbicntr)

AC_SUBST(UNIX_SRC)
AC_SUBST(UNIX_USR_PROJ)

AC_SUBST(compiler)
AC_SUBST(compiler_root)
AC_SUBST(compiler_version)

AC_SUBST(COMPILER)
AC_SUBST(OSTYPE)
AC_SUBST(NCBI_PLATFORM_BITS)

AC_SUBST(NCBI_TEAMCITY_BUILD_NUMBER)
AC_SUBST(NCBI_TEAMCITY_PROJECT_NAME)
AC_SUBST(NCBI_TEAMCITY_BUILDCONF_NAME)
AC_SUBST(NCBI_TEAMCITY_BUILD_ID)
AC_SUBST(NCBI_REVISION)
AC_SUBST(NCBI_SUBVERSION_REVISION)
AC_SUBST(NCBI_SC_VERSION)

#############################################################################
### Create output files and do some post-configuration

## Compose a list of target files
changequote(<<, >>)dnl
x_configurables=`echo "$configurables" | sed 's/:[^:][^:]*\.in//g'`
changequote([, ])dnl

## Deploy the target directory tree
echo "$x_configurables" | while read x_file ; do
   x_dir=`dirname $x_file`
   test -d "$x_dir"  ||  mkdir -p "$x_dir"
done

## Create ncbicfg.c.last if necessary
ncbicfg="$builddir/corelib/ncbicfg.c"
test -f "$ncbicfg" -a ! -f "$ncbicfg.last" && cp -p "$ncbicfg" "$ncbicfg.last"

test -d "$status_dir"  ||  mkdir -p "$status_dir"
CONFIG_STATUS=$status_dir/config.status

## Configure the compiler/flag-dependent header
AC_CONFIG_HEADER(${ncbiconf}:src/build-system/config.h.in)

##
## Configure makefiles, shell scripts, etc.
##
AC_CONFIG_FILES($configurables \
   $srcdir/./Makefile:src/build-system/Makefile.in.top \
   $build_root/inc/common/ncbi_build_ver.h:include/common/ncbi_build_ver.h.in \
   $srcdir/include/common/ncbi_revision.h:include/common/ncbi_revision.h.in)

AC_CONFIG_COMMANDS([default], [
dnl make all shell scripts *.sh be executable
find "$build_root/." -name '*.sh' -print | while read x_file ; do
   chmod a+x "$x_file"
done
chmod a+x "$build_root/build/run_with_cd_reporter.py"

dnl save cache and log files to the build tree dir "status/"
dnl (alongside config.status, which is now directly created there to
dnl avoid possible trouble; for that matter, it can be at least as
dnl important to avoid having config.log still open for writing during
dnl the move).
if test -f config.cache -a -f config.log ; then
   test -d  "$status_dir"  ||  mkdir -p "$status_dir"
   exec AS_MESSAGE_LOG_FD>/dev/null
   mv config.cache config.log "$status_dir"/
   exec AS_MESSAGE_LOG_FD>>"$status_dir/config.log"
fi

dnl Update list of enabled packages
rm -f "$status_dir"/*.enabled
for p in $WithPackages $WithProjects $WithFeatures ; do
   touch "$status_dir"/$p.enabled
done
for p in $WithoutPackages $WithoutProjects $WithoutFeatures ; do
   touch "$status_dir"/-$p.enabled
done

dnl Create dummy .dep files for system installations of (b)zlib.
dnl This is a stopgap measure, and fails for installations in non-system dirs.
# test -f "$status_dir"/LocalZ.enabled  ||  \
#    touch -t 197001010000 $status_dir/.z.dep
# test -f "$status_dir"/LocalBZ2.enabled  ||  \
#    touch -t 197001010000 $status_dir/.bz2.dep

dnl Incorporate any Makefile.*.mk and ncbiconf.*.h files found in the tree.
"$srcdir"/scripts/common/impl/supplement_makefile_mk.sh "$real_srcdir" \
   "$builddir"
find "$srcdir"/src/* -name .svn -prune -o -name 'ncbiconf.*.h' -print \
   | while read x; do
      echo
      echo "/*** Extra macro definitions from $x ***/"
      echo
      echo "#line 1 \"$x\""
      cat "$x"
   done > "$build_root/inc/ncbiconf_extra.h"
if test -s "$build_root/inc/ncbiconf_extra.h"; then
   ncbiconf=$build_root/inc/ncbiconf_unix.h
   newconf=$ncbiconf.extra.new
   savedconf=$ncbiconf.extra.prev
   cat "$ncbiconf" "$build_root/inc/ncbiconf_extra.h" > "$newconf"
   $srcdir/scripts/common/impl/report_duplicates.awk \
      src="$srcdir/src/build-system/config.h.in" "$newconf"
   if test -f "$savedconf"  &&  cmp "$newconf" "$savedconf" >/dev/null; then
      echo "$ncbiconf is unchanged"
   else
      cp -pf "$newconf" "$savedconf"
   fi
   cp -pf "$savedconf" "$ncbiconf"
else
   rm -f "$build_root/inc/ncbiconf_extra.h"
fi

dnl Avoid gratuitous rebuilding
for f in "$builddir/corelib/ncbicfg.c" \
         "$build_root/inc/common/ncbi_build_ver.h"; do
   if test -f "$f.last" && cmp -s "$f.last" "$f"; then
      echo "$f" is unchanged
      touch -r "$f.last" "$f"
   elif test -f "$f"; then
      echo "$f" is updated
      rm -f "$f.last"
      cp -p "$f" "$f.last"
   else
      echo "$f" is not present
   fi
done

dnl Try to build simple helpers
(cd $builddir/build-system/helpers && $MAKE -k)

dnl Generated header containing random compile-time values, produced by
dnl either project_tree_builder (alongside Makefile.flat) or fallback logic.
random_macro="$build_root/inc/ncbi_random_macro.h"
rm -f $random_macro

dnl Create Makefile.flat if requested
if test "$with_configure_dialog" = yes; then
   if test "$with_flat_makefile" = no; then
      AC_MSG_ERROR([incompatible options: --without-flat-makefile but --with-configure-dialog.])
   fi
   with_flat_makefile=yes
elif test "${with_saved_settings:-no}" != no; then
   if test "$with_flat_makefile" = no; then
      AC_MSG_ERROR([incompatible options: --without-flat-makefile but --with-saved-settings.])
   fi
   with_flat_makefile=yes
fi
if test "$with_flat_makefile" != "no"; then
   if test "$with_flat_makefile" = yes; then
      cfm_flags=''
   else
      cfm_flags='-remoteptb'
   fi
   if test -n "$with_projects"; then
      cfm_flags="$cfm_flags -p $with_projects"
   fi
   if test "$with_configure_dialog" = yes; then
      cfm_flags="$cfm_flags -cfg"
   fi
   if test "${with_saved_settings-no}" != no; then
      cfm_flags="$cfm_flags -saved $with_saved_settings"
   fi
   if $real_srcdir/scripts/common/impl/create_flat_makefile.sh "$build_root" \
       -s "$real_srcdir" $cfm_flags  &&  test -f "$builddir/Makefile.flat"; then
      build_flat="Alternatively, cd $builddir && $MAKE -f Makefile.flat"
   elif test -f "$builddir/Flat.configuration_log" \
      -o "$with_flat_makefile" = yes; then
      $EGREP_Q 'Error:|already defined' "$builddir/Flat.configuration_log"
      AC_MSG_ERROR([flat makefile generation failed.])
   fi
fi

if test ! -f "$random_macro"; then
   $real_srcdir/scripts/common/impl/define_random_macros.sh >$random_macro
fi

dnl execute extra-action
if test -n "$with_extra_action" ; then
   with_extra_action=`echo "$with_extra_action" | sed "s%{}%$build_root%g"`
   echo
   echo "executing:  $with_extra_action..."
   eval $with_extra_action
   exit_code="$?"
   if test $exit_code -ne 0 ; then
      AC_MSG_WARN([non-zero exit code ($exit_code):  $with_extra_action])
   fi
   echo
fi

dnl print out additional configuration options
case "$LIB_OR_DLL" in
both) DLL_USAGE="LIBRARIES:  build both static and dynamic by default" ;;
dll)  DLL_USAGE="LIBRARIES:  build as dynamic by default" ;;
lib)
   if test "$with_dll" = "no" ; then
      DLL_USAGE="LIBRARIES:  build as static only"
   else
      DLL_USAGE="LIBRARIES:  build as static by default"
   fi
   ;;
esac

if test -n "$with_projects"; then
    build_proj="To build selected projects (as listed in \"$with_projects\"):
  cd $builddir && $MAKE all_p"
fi

cat << EOCONF
===============================================================================
NCBI C++ Toolkit documentation:
  Online:   https://www.ncbi.nlm.nih.gov/toolkit/doc/book/
  Local:    ./doc/public/index.html
For the available configuration flags run:  ./configure --help

CFLAGS   = $CFLAGS
CXXFLAGS = $CXXFLAGS
CPPFLAGS = $CPPFLAGS
LDFLAGS  = $LDFLAGS

$DLL_USAGE
FEATURES:   $WithFeatures
PACKAGES:
  enabled:  $WithPackages
  disabled: $WithoutPackages
PROJECTS:
  enabled:  $WithProjects
  disabled: $WithoutProjects

Tools / flags / paths:  $builddir/Makefile.mk
Configuration  header:  $ncbiconf

To build everything:  cd $builddir && $MAKE all_r
or simply run $MAKE in the current directory
$build_proj
$build_flat
******* CONFIGURATION SUCCESSFUL *******
EOCONF
], [
PATH="$HOME/bin:/bin:/usr/bin:\$PATH"
status_dir='$status_dir'
builddir='$builddir'
build_root='$build_root'
x_configurables='$x_configurables'
ncbiconf='$ncbiconf'
CFLAGS='$CFLAGS'
CXXFLAGS='$CXXFLAGS'
CPPFLAGS='$CPPFLAGS'
LDFLAGS='$LDFLAGS'
LIB_OR_DLL='$LIB_OR_DLL'
MAKE='$MAKE'
with_dll='$with_dll'
WithFeatures='$WithFeatures'
WithoutFeatures='$WithoutFeatures'
WithPackages='$WithPackages'
WithoutPackages='$WithoutPackages'
WithProjects='$WithProjects $OPT_GROUPS'
WithoutProjects='$WithoutProjects'
with_extra_action='$with_extra_action'
with_projects='$with_projects'
with_flat_makefile='$with_flat_makefile'
with_configure_dialog='$with_configure_dialog'
with_saved_settings='$with_saved_settings'
smart_pwd='$smart_pwd'
real_srcdir='$real_srcdir'
EGREP_Q='$EGREP_Q'
export MAKE PATH
])

AC_WARNING([*** Please don't forget to update .../src/build-system/NEWS if appropriate! ***])dnl
AC_OUTPUT
